【发布时间】:2013-06-14 09:03:14
【问题描述】:
我有一个字符串,里面有一个图像:
"<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"
【问题讨论】:
-
您只在正则表达式中搜索非空白字符,为什么要匹配空格?正则表达式不是匹配 html 的最佳解决方案,最好使用 html/dom 解析器。