[英]Using Regular Expressions in WordPress
我有一个WordPress插件,可以自动检索RSS提要,某些RSS提要以以下格式注入不需要的广告:
src="http://rss.feedsportal.com/c/669/f/9809/s/3b7b71e8/sc/5/mf.gif" border="0" /><br clear='all'/><br /><br /><a href="http://da.feedsportal.com/r/199108411625/u/49/f/9809/c/669/s/3b7b71e8/sc/5/rc/1/rc.htm" rel="nofollow"><img src="http://da.feedsportal.com/r/199108411625/u/49/f/9809/c/669/s/3b7b71e8/sc/5/rc/1/rc.img" border="0" /></a><br /><a href="http://da.feedsportal.com/r/199108411625/u/49/f/9809/c/669/s/3b7b71e8/sc/5/rc/2/rc.htm" rel="nofollow"><img src="http://da.feedsportal.com/r/199108411625/u/49/f/9809/c/669/s/3b7b71e8/sc/5/rc/2/rc.img" border="0" /></a><br /><a href="http://da.feedsportal.com/r/199108411625/u/49/f/9809/c/669/s/3b7b71e8/sc/5/rc/3/rc.htm" rel="nofollow"><img src="http://da.feedsportal.com/r/199108411625/u/49/f/9809/c/669/s/3b7b71e8/sc/5/rc/3/rc.img" border="0" /></a><br /><br /><a href="http://da.feedsportal.com/r/199108411625/u/49/f/9809/c/669/s/3b7b71e8/sc/5/a2.htm"><img src="http://da.feedsportal.com/r/199108411625/u/49/f/9809/c/669/s/3b7b71e8/sc/5/a2.img" border="0" /></a><img width="1" height="1" src="http://pi.feedsportal.com/r/199108411625/u/49/f/9809/c/669/s/3b7b71e8/sc/5/a2t.img" border="0" />
该插件有一个正则表达式搜索和替换工具。 现在,我想查找包含* feedsportal.com的所有字符串/代码行,并替换为null或空值。 此代码应在搜索中添加什么代码,在替换中应添加什么代码?
我还有另一个问题,就是所有导入的帖子图像都左对齐,而我需要将帖子中的所有图像对齐到中心,同时保持文本/段落格式的完整性?
无法就法律问题提供建议,但是在正则表达式上,这是如何清空这些字符串的方法:
$replaced = preg_replace('/"\K[^"]*?feedsportal.*?(?=")/', '', $yourstring);
参见regex演示 。
说明
"
相匹配的开引号 \\K
告诉引擎放弃与最终匹配相距甚远的匹配,它返回 [^"]*?
懒惰地匹配所有不超过引号的字符... feedsportal
.*?
懒惰地匹配任何字符直到... (?=")
可以断言其后的内容是结束语 参考
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.