我试图将CSS样式添加到所有超链接除非它具有“donttouch”属性。preg_replace除非存在字符串
E.g.
- 风格这样的:
<a href="http://whatever.com">style me</a>
- 不要这个样式:
<a href="http://whatever.com" donttouch>don't style me</a>
这里是我的preg_replace没有 “donttouch” 排除,工作正常。
preg_replace('/<a(.*?)href="([^"]*)"(.*?)>(.*?)<\/a>/','<a$1href="$2"$3><span style="color:%link_color%; text-decoration:underline;">$4</span></a>', $this->html)
我看遍了各地,并希望有任何帮助。
为此,您最好使用真正的HTML解析器。 – icktoofay 2013-02-09 22:42:49
或者使用CSS类。 – Arjan 2013-02-09 22:45:36
@Arjan它正在生成一个用于电子邮件的模板,所以CSS类不幸出现问题---所有的CSS都必须内联 – skinnyandbald 2013-02-09 22:46:58