i need regular expression in php to extract image src from following html code
<img class=" wp-image " width="300" height="218" alt="anything" src="image url"></img>
i need regular expression in php to extract image src from following html code
<img class=" wp-image " width="300" height="218" alt="anything" src="image url"></img>
You should use an HTML parser for this. Nevertheless, you can do it using regex with something like this:
<img[^>\/]*src=("(?:[^\"]*)"|'(?:[^\']*)')
The image url would be in capture group 1.
Edit: If you also want to get unqouted src's you can use this:
<img[^>\/]*src=("(?:[^\"]*)"|'(?:[^\']*)'|(?:[^=<>\s\"\'`]+))