正则表达式在PHP中查找HTML“img”元素的“src”属性

前端之家收集整理的这篇文章主要介绍了正则表达式在PHP中查找HTML“img”元素的“src”属性前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个字符串,里面有一个图像:

"<p><img src="http://yahoo.com/testfolder/userdata/editoruploadimages/confused man.jpg" /></p>"

我无法使用正则表达式获取图像URL.我的代码是:

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

代码在遇到映像名称中的空格时停止执行.它只返回“http://yahoo.com/testfolder/userdata/editoruploadimages/confused

返回的字符串应为:
“http://yahoo.com/testfolder/userdata/editoruploadimages/confused man.jpg”

解决方法

我会抓住引号内的所有内容

preg_match_all('/src="([^"]+)"/',$images);

猜你在找的正则表达式相关文章