我有一个字符串,里面有一张图片:
"<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="([^"]+)"/', $questArr_str, $images);
关于php - 在 PHP 中查找 HTML "src"元素的 "img"属性的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17163958/