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*['\"]([^'\"]+)['\"][^>]*>
精彩评论