<?
$string_ScriptName = $_ENV[SCRIPT_NAME];
$array_Number=explode("/",$string_ScriptName);
for($int_i=1;$int_i<count($array_Number)-1;$int_i++){
echo "../";
$s .= "../";
}
?>

解决方案 »

  1.   

    我现在的实现办法就是
    function getdir()
    {
    $Config_DocumentRoot="AAA";
    $count=substr_count(strstr(strtolower($_SERVER['PHP_SELF']),strtolower($Config_DocumentRoot)), "/");
    return ($count==2)?"../":"";
    } // end func
    但这样AAA就不能变更了。
    希望告诉我更新的办法或其它实现跟这类似功能的办法。谢谢
      

  2.   

    不太明白你的意思,在每个a.php中调用getdir()?
    既然是相对路径,参照点总是要有的吧?
      

  3.   

    function getdir()
    {
    $$array_Number=split("/",$_SERVER['PHP_SELF']);
             $s = "";
             for($int_i=1;$int_i<count($array_Number)-1;$int_i++){
        $s .= "../";
             }
    } // end func
      

  4.   

    更正
    function getdir()
    {
    $array_Number=split("/",$_SERVER['PHP_SELF']);
             $s = "";
             for($int_i=1;$int_i<count($array_Number)-1;$int_i++){
        $s .= "../";
             }
    } // end func
      

  5.   

    我也问过一样的问题啊,最后也是用split分割/
    然后选择后 再连接 痛苦啊 笨办法
      

  6.   

    leebx(浩如海)你的函数是得到到整个服务器的根目录吧?比如整个服务器站点的文件夹为webroot,而webroot里包含很多独立的PHP子程序,当然任一个子程序都可能包含多级的目录结构,我现在就是希望在一个独立的具有多级目录结构的PHP子程序中使用相对路径。设a.php文件调用函数getdir(),希望此函数能根据a.php所在目录返回“到站点根目录”的相对路径串。
    如设有某子程序的顶级目录为"webroot/test/my",则
    my/a.php和my/DIR/b.php都调用getdir()时应分别返回""与"../"。
    这里不一定是要返回"../"什么的,只是要这种实现相对路径的功能。
    不知有什么好的实现办法?