Home  >  Article  >  Backend Development  >  求一正则

求一正则

WBOY
WBOYOriginal
2016-06-20 12:43:00771browse

$str = "图片1:<img  src='1.jpg' alt="求一正则" >,图片2:<img  src=\"2.jpg\" alt="求一正则" >";


匹配出$str内src里面的内容的正则应该怎么写?


回复讨论(解决方案)

$str = "图片1:<img  src='1.jpg' alt="求一正则" >,图片2:<img  src=\"2.jpg\" alt="求一正则" >";preg_match_all('/src=([\'"])(.+)\1/isU', $str, $m);print_r($m);
Array(    [0] => Array        (            [0] => src='1.jpg'            [1] => src="2.jpg"        )    [1] => Array        (            [0] => '            [1] => "        )    [2] => Array        (            [0] => 1.jpg            [1] => 2.jpg        ))

一定要把单引号、双引号也匹配出来吗?

那就不明白你在想什么了

好吧,多谢老徐回答。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn