将html代码中的图片src相对路径,替换为绝对路径;
if (preg_match_all('/<img.+src=\"?(.+\.(jpg|gif|bmp|png))\".+\"?\/>/i',$content,$TagArr))
{
foreach ($TagArr as $ValArr)
{
$JDPath=substr($ValArr[0],strpos($ValArr[0],'=')+4,-1);//http路径
$Pathpic="E:/anlee/APMServ/www/htdocs".$JDPath;//
$tcontent=preg_replace($ValArr[0],$Pathpic,$tcontent);
}
return $tcontent;
}
if (preg_match_all('/<img.+src=\"?(.+\.(jpg|gif|bmp|png))\".+\"?\/>/i',$content,$TagArr))
{
foreach ($TagArr as $ValArr)
{
$JDPath=substr($ValArr[0],strpos($ValArr[0],'=')+4,-1);//http路径
$Pathpic="E:/anlee/APMServ/www/htdocs".$JDPath;//
$tcontent=preg_replace($ValArr[0],$Pathpic,$tcontent);
}
return $tcontent;
}
你的$ValArr[0] 不是正则表达式吧
只是替换用 mixed str_replace ( mixed search, mixed replace, mixed subject [, int &count] ) 这个函数就可以了
你不会把图片的地址换成 "E:/anlee/APMServ/www/htdocs" 这个吧
{
foreach ($TagArr as $ValArr)
{
$JDPath=substr($ValArr[0],strpos($ValArr[0],'=')+4,-1);//http路径
$Pathpic="E:/anlee/APMServ/www/htdocs".$JDPath;//
$tcontent=preg_replace($ValArr[0],$Pathpic,$tcontent);
}
return $tcontent;
}
我想用这段代码,替换$content(为html代码)中的src的相对地址。然后用phpmailer的AddEmbeddedImage函数实现嵌入图片到邮件中。$Idx=0;
if(preg_match_all('/<img(\s+\w+=[\'\"]?\w+[\'\"]?)?src=[\'\"]?(\w+\.(jpg|gif|bmp|png))[\'\"]?(\s+\w+=[\'\"]?\w+[\'\"]?)?/i'/*'/<img.+src=\"?(.+\.(jpg|gif|bmp|png))\".+\"?\/>/i'*/,$tcontent,$array))
{
foreach ($array as $arrayArr)
{
$CID=md5("PIC_".$Idx++);
$Path=substr($arrayArr[0],strpos($arrayArr[0],'=')+2,-1);//用来替代cid
$mail->AddEmbeddedImage($Path,$CID, "");
//$Pattern="'$Pathi";
$Mcontent=str_replace($arrayArr[0],"cid:".$CID,$tcontent);
}
return $Mcontent;
}
我是用FCKeditor作为邮件编辑器的。想发送嵌入图片的html邮件。
$html = "<img src='a/b/c.jpg' />1dsadasd<br />dasd111<a href='http://www.google.com.hk' />adadsad<img src='1/2/3.png' />";$rootPath = 'E:/anlee/APMServ/www/htdocs'; echo preg_replace('/(<img.*?)([^\"\'\s]+\.jpg|gif|bmp|png)(.*?\/?>)/is', '\\1'.$rootPath.'\\2\\3', $html );
是这意思吗?