PHP code example of backendtea / fourchanapi

1. Go to this page and download the library: Download backendtea/fourchanapi library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

backendtea / fourchanapi example snippets


use FourChan\FourChan;

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

use FourChan\FourChan;

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

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


$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();