'''php
//先定义一个获取所有图片的函数
function getSrc($content){
$pattern="/<[img|IMG].*?src=[\\\"|\\\'|\'|\"](.*?(?:[\.gif|\.jpg|\.png|\.jpeg|\.bmp]))[\\\"|\\\'|\"|\'].*?[\/]?>/i";
preg_match_all($pattern,$content,$match);
return $match;
}
//字符串
$str = ' <img src=\"http://127.0.0.1/file/upload/201503/24/1.jpg\" width=\"554\" height=\"416\" alt=\"\" />
<img src="http://127.0.0.1/file/upload/201503/24/2.jpg" width=\"550\" height=\"775\" alt=\"\" />
<img src="http://127.0.0.1/file/upload/201503/24/3.jpg" width=\"336\" height=\"508\" alt=\"\" />';
//获取并且输出
print_r(getSrc($str));
//输出内容如下
/*
Array
(
[0] => Array
(
[0] => <img src=\"http://127.0.0.1/file/upload/201503/24/1.jpg\" width=\"554\" height=\"416\" alt=\"\" />
[1] => <img src="http://127.0.0.1/file/upload/201503/24/2.jpg" width=\"550\" height=\"775\" alt=\"\" />
[2] => <img src="http://127.0.0.1/file/upload/201503/24/3.jpg" width=\"336\" height=\"508\" alt=\"\" />
)
[1] => Array
(
[0] => "http://127.0.0.1/file/upload/201503/24/1.jpg
[1] => http://127.0.0.1/file/upload/201503/24/2.jpg
[2] => http://127.0.0.1/file/upload/201503/24/3.jpg
)
)
//为啥$str[1][0]开头的地方会带双引号呢?怎么写才能让它不带双引号
*/
1
lianyue 2015-03-25 12:56:32 +08:00
[\\\"|\\\'|\'|\"]
换成 () 括号 (\\\"|\\\'|\'|\") |
4
kungfuchicken 2015-03-25 13:25:53 +08:00
<img.*?src=\\?(?:\'|\")(.*?\.(?:gif|jpg|png|jpeg|bmp]))\\?(?:\'|\").*?\/?>
|
5
kungfuchicken 2015-03-25 13:27:03 +08:00
<img.*?src=\\?(?:\'|\")(.*?\.(?:gif|jpg|png|jpeg|bmp))\\?(?:\'|\").*?\/?>
更正一下 |