Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php中的正则表达式从以下html代码中提取图像src_Php_Regex - Fatal编程技术网

php中的正则表达式从以下html代码中提取图像src

php中的正则表达式从以下html代码中提取图像src,php,regex,Php,Regex,我需要用php正则表达式从下面的html代码中提取图像src <img class=" wp-image " width="300" height="218" alt="anything" src="image url"></img> 您应该为此使用HTML解析器。不过,您可以使用regex这样做: <img[^>\/]*src=("(?:[^\"]*)"|'(?:[^\']*)') 图像url将位于捕获组1中 编辑:如果您还想获得未经验证的src,您可以

我需要用php正则表达式从下面的html代码中提取图像src

<img class=" wp-image " width="300" height="218" alt="anything" src="image url"></img>

您应该为此使用HTML解析器。不过,您可以使用regex这样做:

<img[^>\/]*src=("(?:[^\"]*)"|'(?:[^\']*)')
图像url将位于捕获组1中

编辑:如果您还想获得未经验证的src,您可以使用:

<img[^>\/]*src=("(?:[^\"]*)"|'(?:[^\']*)'|(?:[^=<>\s\"\'`]+))

在发布一个没有引用src=image等src链接的问题之前,你需要进行研究。png@Atul古普塔,谢谢,我甚至不知道那是有效的HTML