php中使用preg_match_all匹配文章中的图片
发布时间:2020-12-13 06:14:03 所属栏目:PHP教程 来源:网络整理
导读:preg_match_all 函数:int preg_match_all ( string pattern,string subject,array matches [,int flags] )执行一个全局正则表达式匹配 在 subject 中搜索所有与 pattern 给出的正则表达式匹配的内容并将结果以 flags 指定的顺序放到 matches 中。 搜索到第
preg_match_all 函数:int preg_match_all ( string pattern,string subject,array matches [,int flags] )执行一个全局正则表达式匹配 例子: 代码如下: $con = file_get_contents("//www.52php.cn/news/jb-1.html");
$pattern="/<[img|IMG].*?src=['|"](.*?(??1))['|"].*?[/]?>/"; preg_match_all($pattern,$con,$match); print_r($match); ?> 结果: 代码如下: Array ( [0] => Array ( [0] => ![]() [1] => ![]() [2] => ![]() ) [1] => Array ( [0] => //www.52php.cn/usr/themes/dddefault/images/logo.png [1] => //www.52php.cn/usr/uploads/2012/09/531656480.jpg [2] => //www.52php.cn/usr/uploads/2012/09/2647136297.jpg ) ) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |