Home > Backend Development > PHP Tutorial > 正则表达式如何匹配不带某字符串的img标签呢?

正则表达式如何匹配不带某字符串的img标签呢?

WBOY
Release: 2016-06-06 20:21:57
Original
1375 people have browsed it

<code>$content = preg_replace('/<img  alt="正则表达式如何匹配不带某字符串的img标签呢?" >/i', "<img  rel='\"lazyload\"' src="%5C%22%7B%24tpl_url%7D/img/lazy_loading.gif%5C%22%5C%243" alt="正则表达式如何匹配不带某字符串的img标签呢?" >", $content);</code>
Copy after login
Copy after login

目前的代码是这样,请问以上的正则如何改成只匹配不带data-nolazyload的img标签呢?
example:
正则表达式如何匹配不带某字符串的img标签呢?不匹配
正则表达式如何匹配不带某字符串的img标签呢?匹配

回复内容:

<code>$content = preg_replace('/<img  alt="正则表达式如何匹配不带某字符串的img标签呢?" >/i', "<img  rel='\"lazyload\"' src="%5C%22%7B%24tpl_url%7D/img/lazy_loading.gif%5C%22%5C%243" alt="正则表达式如何匹配不带某字符串的img标签呢?" >", $content);</code>
Copy after login
Copy after login

目前的代码是这样,请问以上的正则如何改成只匹配不带data-nolazyload的img标签呢?
example:
正则表达式如何匹配不带某字符串的img标签呢?不匹配
正则表达式如何匹配不带某字符串的img标签呢?匹配

img(.+)src换成img src

img(.+)src 换成 img(.*?)src 试试?

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template