加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-14 06:06:52 所属栏目:百科 来源:网络整理
导读:我有一个字符串,里面有一个图像: "pimg src="http://yahoo.com/testfolder/userdata/editoruploadimages/confused man.jpg" //p" 我无法使用正则表达式获取图像URL.我的代码是: preg_match_all("/src=([^s]+)/",$questArr_str,$images); 此代码在遇到映
我有一个字符串,里面有一个图像:

"<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);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读