大家好,我属于比较菜鸟级别的php编程,现在遇到一个问题,就是我的代码都没有问题,在putty调试下都能正常运行已经正常显示,可是在浏览器中就显示不出来。这类代码都有关screen scraping类的。比如,一段很简单的代码<?php$url="http://www.onion.com/";
$data=file_get_contents($url);
$start_index=stripos($data,"<h3>");
$end_index=stripos($data,"</h3>");$h1=substr($data,$start_index,($end_index-$start_index)+5);echo "$h1\n";
echo "data";?>data是可以在浏览器中运行出来的,但是抓取的$h1就不能显示了。
用putty调试,就可以正常输出。我搜了很多,实在不知道什么问题,比较初级的编程,谢谢大家了!!

解决方案 »

  1.   

    将$start_index,$end_index都echo出来看看。
      

  2.   


    <?php$url="http://www.onion.com/";
    $data=file_get_contents($url);
    $start_index=stripos($data,"<h3>");
    $end_index=stripos($data,"</h3>");$h1=substr($data,$start_index,($end_index-$start_index)+5);echo "$h1\n";
    echo "$data";?>echo "data";
    应该为echo "$data";
      

  3.   

    echo "$h1\n";
    echo "data";
    这里的h1有必要带引号吗,另外echo "data";这个是啥意思?不是直接输出data这四个字母吗。
    应该是echo $h1."\n";echo $data;吧!
      

  4.   

    谢谢啦 echo"data"只是测试的代码,我想看看这个data字符串能不能输出。结果就是字符处可以在浏览器里面输出,但是动态抓取的东西就没办法显示出来了~
    问题在于在命令行下可以显示,浏览器中显示不了。我试了很多台机器也都更改了浏览器设置,还是不行~