backendtea/fourchanapi

此包已被弃用且不再维护。未建议替代包。

4chan api的PHP包装器

v1.0.0 2017-10-20 18:41 UTC

This package is not auto-updated.

Last update: 2020-01-24 17:11:54 UTC


README

Build Status Code Climate Code Climate Code Climate

4chan api的PHP API包装器。

请参阅https://github.com/4chan/4chan-API了解使用规则。

安装

运行composer require backendtea/fourchanapi ^1.0 了解Composer的信息,请访问他们的网站

使用

获取/v/中所有帖子的编号列表

use FourChan\FourChan;

FourChan::board('v')->getThreads();

抓取我们在/v/找到的第一个帖子的所有图片

use FourChan\FourChan;

$posts = FourChan::board('v')->getThreads()[0]->getPosts();

foreach($posts as $post) {
    if ($post->hasimage() {
        echo $post->getImageUrl();
    }
}

与获取图片信息相关的任何函数在无图片时都会抛出FourChan\Util\NoImageException异常。所以另一种方法可以是


$posts = FourChan::board('a')->getThreads()[0]->getPosts();

foreach($posts as $post) {
    try{
        echo $post->getImageUrl();
    } catch(NoImageException $e) {
        //do nothing
    }
}

获取帖子的信息

$thread = FourChan::board('a')->getThreads()[0];

// true or false
$thread->isStick();
//true or false
$thread->isClosed();
//true or false
$thread->isArchived();
//Subject or '' if no subject is set.
$thread->getSubject();
//# of OP
$thread->getID();

获取帖子的信息

$post = FourChan::board('a')->getThreads()[0]->getPosts()[0];
//Comment of the post, including escaped html.
$post->getFullComment();
//# of the post
$post->getID();

如果您需要更多功能,可以自己制作并发送PR,或者创建Github上的问题,希望我或其他人为您完成。

贡献

欢迎功能、错误修复等,请查看Contributing.md以获取更多信息

注意

所有虚假响应均从4chan的实时帖子中抓取,它们不一定代表我的观点或参与此项目的任何人的观点。