计算图片路径 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;}自己写了我把代码贴出来 要的拷过去 新手 $db=dblink(); 这个是mysql那个类啊 谢谢? happy PHP! php+MySQL 联级下拉框 新手求助,关于密码修改的问题 从已有表中查询数据并批量插入到结构不相同的另一个表中 为什么我加了header还让我下载图片呢 PHP, 能否向Excel 写入和读出数据? 求高手推荐一个CMS,要求PHP4+MYSQL+SMART+MVC 关于静态模版 php存数据到数据库,echo出来的sql可正常在mysql里执行但是放在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;
}自己写了我把代码贴出来 要的拷过去