各位大侠,现在我碰到这么一个奇怪的问题。
我用file_get_contents函数把模板文件读取出来,如果里面的链接这样写<a href="/index.php">链接</a>
读取到字符串就会变成<a href="/www/index.php">链接</a>
如果是<a href="index.php">链接</a>,就不会变。
www是我放页面文件的文件夹名称。
空间我是使用的新网的虚拟主机,unix系统。先行拜谢!

解决方案 »

  1.   

    不是php的问题,可能你的后台系统会自动添加这个。
      

  2.   

    to dream1206:
    我自己写的测试页面如下
    <?php
    require_once(dirname(__FILE__) . '/app.php');
    //echo($WEB_ROOT.'<br />');
    //echo($INI['skin']['template']);
    $tFile = 'test';
    $tFileN = preg_replace( '/\.html$/', '', $tFile);
    $tFile = DIR_TEMPLATE . '/' . $tFileN . '.html';
    $cFile = DIR_COMPILED . '/' . str_replace('/','_',$tFileN) . '.php';
    $fileContent = file_get_contents($tFile);
    echo('1:'.$DIR_TEMPLATE.'<br />');
    echo('2:'.$tFileN.'<br />');
    echo('3:'.DIR_TEMPLATE . '/' . $tFileN . '.html'.'<br />');
    echo('目录:'.$tFile.'<br />');
    //$fileContent = preg_replace( '/^(\xef\xbb\xbf)/', '', $fileContent ); //EFBBBF   
    $fileContent = str_replace( '/www', '', $fileContent); //
    echo($fileContent);
    ?>这样应该不是后台自己添加的问题了吧
      

  3.   

    确实好像是有的地方自动添加,我再找找看
    吧引用的app.php去掉就不会有这问题了。
      

  4.   

    你那些常量从哪里来的,肯定不是 php 原生的
      

  5.   

    file_get_contents获取的东西会自动改变,不会吧。是不是显示的时候做了特殊处理
      

  6.   

    我真晕了,一句一句的注释来测试 static private $_begin = 0;
    static private $_instance = null;
    static private $_debug = false; static public function Init($debug=false)
    {
    self::$_instance = new Session();
    self::$_debug = $debug;
    session_start();
    }红色的这句注释掉就没事了,这是为什么?
      

  7.   

    刚才的排版有点问题
    有这样一个类
    class Session
    self::$_instance = new Session();//注释掉这句就没事function __construct()
    {
    self::$_begin = microtime(true);
    }这是构造函数
      

  8.   

    但是在这个Sesssion类中并没有看到解析模板文件并替换超链接的代码呀,你看到了吗?
    何况你注释掉它后程序不报错吗?如果不报错,那么这个对象又有什么用?
      

  9.   

    谢谢大家了,测试了一晚上,总算找到问题所在$document_root = $_SERVER['DOCUMENT_ROOT'];
    $docroot = rtrim(str_replace('\\','/',$document_root),'/');
    if(!$docroot) {
    $script_filename = $_SERVER['SCRIPT_FILENAME'];
    $script_filename = str_replace('\\','/',$script_filename);
    $script_name = $_SERVER['SCRIPT_NAME'];
    $script_name = str_replace('\\','/',$script_name);
    $lengthf = strlen($script_filename);
    $lengthn = strlen($script_name);
    $length = $lengthf - $lengthn;
    $docroot = rtrim(substr($script_filename,0,$length),'/');
    }
    $webroot = trim(substr(WWW_ROOT, strlen($docroot)), '\\/');
    echo($webroot);这一段代码在win系统+iis下没问题,在linux下就会多出一段来,可折腾死我了
    再次谢谢大家,结贴!