//用*替换内容中,7位以上的数字中的最后6位,如果6位数字在图片 <img /> 中就不替换6数字。
$text = preg_replace("/\d{6}\b/", '******', $text); <img border=\"0\" src=\"http://wenwen.cardbaobao.com/attachments/1/u_1/10_11/19_10_58_57_170954.jpg\" />
但是我的图片中也有6位或以上的数字,也会被替换,结果显示不出图片。
<img border=\"0\" src=\"http://wenwen.cardbaobao.com/attachments/1/u_1/10_11/19_10_58_57_******.jpg\" />请问怎么让图片正常显示啊,但文章内容的6位或以上的数字为******,7******,88******?
$text = preg_replace("/\d{6}\b/", '******', $text); <img border=\"0\" src=\"http://wenwen.cardbaobao.com/attachments/1/u_1/10_11/19_10_58_57_170954.jpg\" />
但是我的图片中也有6位或以上的数字,也会被替换,结果显示不出图片。
<img border=\"0\" src=\"http://wenwen.cardbaobao.com/attachments/1/u_1/10_11/19_10_58_57_******.jpg\" />请问怎么让图片正常显示啊,但文章内容的6位或以上的数字为******,7******,88******?
123456 sad";
echo $text = preg_replace("/(>.*)\d{6}\b/s", '$1******', $text); out:
<img border="0" src="http://wenwen.cardbaobao.com/attachments/1/u_1/10_11/19_10_58_57_170954.jpg" />
****** sad
中的$1是什么啊?
preg_replace("/\d{6}[^\.]/",'******',$str);
要的是最后6位数字为******
$text = "123456789 <img border=\"0\" src=\"http://wenwen.cardbaobao.com/attachments/1/u_1/10_11/19_10_58_57_170954.jpg\" />
123456 sad";
echo $text = preg_replace("/(>.*)\d{6}\b/s", '$1******', $text); out:
123456789 <img border="0" src="http://wenwen.cardbaobao.com/attachments/1/u_1/10_11/19_10_58_57_170954.jpg" />
****** sad而不是我想要的:
123****** <img border="0" src="http://wenwen.cardbaobao.com/attachments/1/u_1/10_11/19_10_58_57_170954.jpg" />
****** sad
123412213123312356a<img src=\"13123123123.jpg\"> sad<img border=\"0\" src=\"http://wenwen.cardbaobao.com/attachments/1/u_1/10_11/19_10_58_57_170954.jpg\" />131231231231啊213412312312s";$temp = preg_split('/(<[^<>]*>)/s', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
$res = '';
foreach($temp AS $v)
{
if(preg_match('/(<[^<>]*>)/', $v))
{
$res .= $v;
}
else
{
$res .= preg_replace('/(.*?)\d{6}(\b|[^\d])/s', '$1******$2', $v);
}
}
echo $res;