应该怎么获取test2.php中的返回值呢?

解决方案 »

  1.   

    'test2.php?id=1'是url,'test2.php'是本地文件名。
    假设test.php 和 test2.php都放在documentRoot下。test.php 
    <?php 
    ob_start();
    include( "http://localhost/test2.php?id=1");
    $a = ob_get_contents();
    ob_end_clean();
    print_r($a); 
    //或者$a = file_get_contents('http://localhost/test2.php?id=1')
    ?> test2.php 
    <?php 
    if($id==   1) 

    $data   =   "this   is   no.1 "; 

    else 

    $data   =   "this   isn 't   no.1 "; 

    echo $data; 
    ?> 
      

  2.   

    require()语句支持返回值,include()不支持吧
      

  3.   

    应该不是这样的。
    错误提示是传递的变量出了问题,如果test.php修改为:
    test.php 
    <?php 
    $a   =   include( "test2.php"); 
    print_r($a); 
    ?> 就可以返回值。难道include中包含的文件不能传递变量吗??哪位高手有这方面的经验?
      

  4.   

    经过测试,可以通过全局变量传递数值给test2.php来解决。不知道大家还有其他高见吗?