【发布时间】:2014-12-07 08:58:06
【问题描述】:
我的 preg_replace 有问题,我的函数有一些错误,我不知道在哪里。 我需要从数组中删除所有来源不是我的主域的图像。
这是我的功能:
$aPatterns = array (
(...),
'#<img[^>]+src="(?!http://example.com/emoticon/(example|emot|name).gif)[^\s]+"[^>]+>#is',
(...));
$aReplecements = array(
(...),
'',
(...)
);
$contentOut = preg_replace($aPatterns,$aReplecements,$content);
如果img标签没有关闭或者src属性函数末尾没有双引号符号不起作用,则不更改为空字符串。
我不知道这个表达有什么问题,我希望,我指望你的帮助。
问候,
【问题讨论】:
-
抱歉,不确定,但是:你的意思是当你有
<img src="http://exammple.com/emoticon/example.gif">这样的东西时它可以工作,但是当你有<img src=http://exammple.com/emoticon/example.gif>时它不起作用? -
是的,我不知道问题出在哪里。
标签: php regex image preg-replace