计算图片路径 http://localhost/ 这个那里来的 =.=|| 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 路径应该是这个http://localhost/../../template_class/tp03/image/1_pic.gif 这个可以这样的:<?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.gifecho $x;//输出替换后的变量X的值,最终结果?> 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没多少关系就计算这个吧 //根据两个相对路径计算图片相对路径/* * @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;}自己写了我把代码贴出来 要的拷过去 哪位帮忙解决下,遍历数组,合并相同的值,保留不同的值 高手进来。php session一直没过期,过来三天,打开是是一样的。 PHP MYSQL 画图生成的颜色问题 花小钱请哪位大哥做个DZ远程附件发表时自动上传 又是install问题?? php登录验证时的一个问题 字符串截取乱码问题 帮忙解释一下下面的概念 高分寻找php新闻更新系统~ 求一个PHP中类的封装的例子 jquery+上传文件 的相关问题
http://localhost/../../template_class/tp03/image/1_pic.gif
<?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的值,最终结果
?>
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没多少关系
就计算这个吧
//根据两个相对路径计算图片相对路径
/*
* @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;
}自己写了我把代码贴出来 要的拷过去