PHP web爬虫程序返回“未识别的偏移量1”错误
我有这个脚本,我试图提取链接和文本从一个网站,并张贴在我的页面。虽然它像一个符咒一样工作,但它也在顶部显示一个错误,即PHP web爬虫程序返回“未识别的偏移量1”错误,php,web-crawler,Php,Web Crawler,我有这个脚本,我试图提取链接和文本从一个网站,并张贴在我的页面。虽然它像一个符咒一样工作,但它也在顶部显示一个错误,即未识别的偏移量1。 帮我把它猜出来 代码如下: <?php function get_data($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
未识别的偏移量1
。
帮我把它猜出来
代码如下:
<?php
function get_data($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL,$url);
$result=curl_exec($ch);
curl_close($ch);
return $result;
}
$returned_content = get_data('http://www.usmle-forums.com/usmle-step-1-forum/');
$first_step = explode( '<tbody id="threadbits_forum_26">' , $returned_content );
$second_step = explode('</tbody>', $first_step[1]);
$third_step = explode('<tr>', $second_step[0]);
// print_r($third_step);
foreach ($third_step as $element) {
$child_first = explode( '<td class="alt1"' , $element );
$child_second = explode( '</td>' , $child_first[1] );
$child_third = explode( '<a href=' , $child_second[0] );
$child_fourth = explode( '</a>' , $child_third[1] );
echo $final = "<a href=".$child_fourth[0]."</a></br>";
}
?>
var\u dump($child\u first)M A SIDDIQUI我应该在哪里插入这个var\u dump($child\u first)代码>我确实在后面插入了,但它在屏幕上显示了整个代码注释掉您的最后一行,然后转储第一个孩子查看输出最后一行的含义是什么echo$final=“在此之前$child\u second=explode(“”,$child\u first[1]);