PHP json,查找信息并将其与4chan api链接


PHP json, finding info and linking it with 4chan api

如果我想在4chan上回显一个通用线程的链接。

以下是我的想法,但我不知道该怎么做

$jsonurl = "http://a.4cdn.org/vg/catalog.json";
$json = file_get_contents($jsonurl);
$json_output = json_decode($json);
foreach( $json_output as $no )
{
    if(strpos(sub, 'DOTA')) { //Not sure how I would do this
        //echo the "no" of it in the json
    }
}

必须查看JSON数据才能查看您要查找的内容。试试

$jsonurl = "http://a.4cdn.org/g/catalog.json";
$json = file_get_contents($jsonurl);
$json_output = json_decode($json);
foreach ($json_output as $page) {
    foreach($page->threads as $thread) {
        if (isset($thread->sub)) {
            $sub = $thread->sub;
            $no  = $thread->no;
            echo $sub . ', Thread Number: ' . $no . '<br />';
            /*
            if (strpos($sub, 'DOTA') !== false) {
                echo 'Found DOTA!!! Thread Number is: ' . $thread->no;
            } 
            */
        }
    }
}

您应该研究接收到的JSON数据,以便了解如何提取数据。这是一种方法:

foreach( $json_output as $page ) {
  foreach ($page->threads as $t) { 
    echo 'http://boards.4chan.org/vg/res/' . $t->no . ', ';
  }
}