http://localhost/ 这个那里来的 =.=||

解决方案 »

  1.   

    路径应该是这个
    http://localhost/../../template_class/tp03/image/1_pic.gif
      

  2.   

    这个可以这样的:
    <?php
    //假如:../../template_class/tp03/style.css是变量x,image/1_pic.gif是变量y
    $x=str_replace("../../","http://localhost/",$x);//把../../替换为http://localhost/
    $temp=basename($x);//取得style.css的值
    $x=str_replace($temp,$y,$x)//替换style.css的字符串为变量Y的值image/1_pic.gif
    echo $x;//输出替换后的变量X的值,最终结果
    ?>
      

  3.   

    2楼正解呵呵{ 
    back-ground:url(image/1_pic.gif); } 可是这个地址是有变化的
    可能是这样{ 
    back-ground:url(./image/1_pic.gif); } 或者是{ 
    back-ground:url(../image/1_pic.gif); } ../../template_class/tp03/image/1_pic.gif这个localhost没多少关系
    就计算这个吧
      

  4.   


    //根据两个相对路径计算图片相对路径
    /*
     * @param string $parent_filepath
     *  父文件的路径 一般是css文件
     * @param string $filepath
     *  css文件中包含的图片路径
     *
     */
    function get_img_relativepath($parent_filepath,$filepath)
    {
    //获取父文件的路径 不包换文件命
    $parent_path = dirname($parent_filepath)."/";
    //计算子文件需要向上级返回的文件层数
    $matchtimes = preg_match_all("/(\.\.\/)/",$filepath,$match);

    for($i = 0;$i<$matchtimes;$i++)
    {
    if(!preg_match("/\/[a-zA-Z0-9_\.]+\/$/",$parent_path))
    $parent_path = preg_replace("/^[(\.\/)|(\.\.\/)|(\/)]*/",'',$parent_path);
    else
    // 替换 /string/这种
    $parent_path = preg_replace("/\/[a-zA-Z0-9_\.]+\/$/","/",$parent_path);
    }
    $path = $parent_path.preg_replace("/^[(\.\/)|(\.\.\/)|(\/)]*/",'',$filepath);
    return $path;
    }自己写了我把代码贴出来 要的拷过去