san san - 5 months ago 24
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="http://yahoo.com/testfolder/userdata/editoruploadimages/confused 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
"http://yahoo.com/testfolder/userdata/editoruploadimages/confused


The returned string should be:
"http://yahoo.com/testfolder/userdata/editoruploadimages/confused man.jpg"

san san
Answer

Thank every one for helping me out.

I found my solution by using:

pattern = "/src=([^\\\"]+)/"
Comments