php - 在 PHP 中查找 HTML "src"元素的 "img"属性的正则表达式

标签 php html regex

我有一个字符串,里面有一张图片:

"<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/

相关文章:

html - css ~ 选择器不会将样式应用于所有目标元素(z-index 到下一个/上一个标签)

regex - 在多种文件类型的查找命令中使用正则表达式

php - Symfony - 使用来自另一个包的服务

php - 什么是好的免费在线投票/调查应用程序?

php - DOMDocument 对我的字符串做了什么?

php - 将 mysql 结果返回到 php 字符串

html - Css: 不能改变 <li> 的大小

html - CSS - 动态文本旁边的 slider 对齐

javascript - 有效生成带反斜杠的文件夹路径

regex - 从文件名和路径解析日期和时间