san san - 2 years ago 79
HTML Question

Regular expression to find "src" attribute of HTML "img" element in PHP

I have a string, inside of that I have an image:

"<p><img src=" man.jpg" /></p>"

I could not fetch the image URL with my regular expression. My code is:

preg_match_all("/src=([^\\s]+)/", $questArr_str, $images);

This code stops its execution when it encounters the space in the image name. It only returns

The returned string should be:
" man.jpg"

san san
Answer Source

Thank every one for helping me out.

I found my solution by using:

pattern = "/src=([^\\\"]+)/"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download