欢迎来到代码驿站!

PHP代码

当前位置:首页 > 软件编程 > PHP代码

PHP提取数据库内容中的图片地址并循环输出

时间:2021-04-20 08:58:27|栏目:PHP代码|点击:
复制代码 代码如下:

/*
1 (?s) 代表 Pattern.DOTALL,也就是匹配换行,允许 img里出现在多行
2 .*?代表非贪婪匹配任意字符,直到后面的条件出现
3 ?: 代表这个匹配但不被捕获,也就是不在结果出现 [\.gif|\.jpg] 是或者的意思
*/
$pattern="/<img.*?src=[\'|\"](.*?(?:[\.gif|\.jpg]))[\'|\"].*?[\/]?>/";
$str='<p style="padding: 0px; margin-top: 0px; margin-bottom: 0px; line-height: 200%;"><img border="0" src="upfiles/2009/07/1246430143_4.jpg" alt=""/></p><p style="padding: 0px; margin-top: 0px; margin-bottom: 0px; line-height: 200%;"><img border="0" src="upfiles/2009/07/1246430143_3.jpg" alt=""/></p><p style="padding: 0px; margin-top: 0px; margin-bottom: 0px; line-height: 200%;"><img border="0" src="upfiles/2009/07/1246430143_1.jpg" alt=""/></p>';
preg_match_all($pattern,$str,$match);
print_r($match);
/*
Array
(
[0] => Array
(
[0] => <img border="0" src="upfiles/2009/07/1246430143_4.jpg" alt=""/>
[1] => <img border="0" src="upfiles/2009/07/1246430143_3.jpg" alt=""/>
[2] => <img border="0" src="upfiles/2009/07/1246430143_1.jpg" alt=""/>
)
[1] => Array
(
[0] => upfiles/2009/07/1246430143_4.jpg
[1] => upfiles/2009/07/1246430143_3.jpg
[2] => upfiles/2009/07/1246430143_1.jpg
)
)
*/

上一篇:php摘要生成函数(无乱码)

栏    目:PHP代码

下一篇:thinkPHP控制器变量在模板中的显示方法示例

本文标题:PHP提取数据库内容中的图片地址并循环输出

本文地址:http://www.codeinn.net/misctech/105242.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有