开发者

Very simple editing in a regular expression pattern

How can I tranform this rege开发者_JS百科x to search only in src=* and not all the links that start with http and end with jpg, png, gif? Additionally I want to get the https images. Thank you!

preg_match('!http://.+\.(?:jpe?g|png|gif)!Ui' , $content , $matches);


Prefix your regex with a negative assertion to filter out the common occurences:

 (?<!src=["\']|src=)

"Prefixing" means after your ! and before the https?://..

preg_match('!(?<!src=["\']|src=)http://.+\.(?:jpe?g|png|gif)!Ui' , $content , $matches);


You can try this one, that catches only the src tag and select the image url:

<img[^>]+src\s*=\s*['\"]([^'\"]+)['\"][^>]*>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜