正则表达式来查找“src” HTML的属性“img”元素在PHP中 [英] Regular expression to find "src" attribute of HTML "img" element in PHP

查看:116
本文介绍了正则表达式来查找“src” HTML的属性“img”元素在PHP中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



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

我无法使用正则表达式获取图片网址。我的代码是:

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

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



返回的字符串应该是:
http://yahoo.com/testfolder/userdata/editoruploadimages/confused man.jpg



我使用以下方式找到了解决方案:

  pattern =/ src =([^ \\\\] +)/


I have a string, inside of that I have an image:

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

I could not fetch the image URL with my regular expression. My code is:

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

This code stops its execution when it encounters the space in the image name. It only returns "http://yahoo.com/testfolder/userdata/editoruploadimages/confused

The returned string should be: "http://yahoo.com/testfolder/userdata/editoruploadimages/confused man.jpg"

解决方案

Thank every one for helping me out.

I found my solution by using:

pattern = "/src=([^\\\"]+)/"

这篇关于正则表达式来查找“src” HTML的属性“img”元素在PHP中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆