加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

PHP如何用正则取得所有图片的路径

发布时间:2020-12-13 20:54:53 所属栏目:PHP教程 来源:网络整理
导读:问题: 如下面内容,两个问题: 1、用正则取得所有图片地址的php语句怎么写? 2、取出的多个地址如何一条一条地保存到数据库中? pimg alt= width=153 src=/upload/2009-11-15/9_3.jpg height=60 /img src=/upload/2009-11-15/58263668.png alt= /img width=

问题:

 如下面内容,两个问题:
1、用正则取得所有图片地址的php语句怎么写?
2、取出的多个地址如何一条一条地保存到数据库中?

<p><img alt="" width="153" src="/upload/2009-11-15/9_3.jpg" height="60" /><img src="/upload/2009-11-15/58263668.png" alt="" /><img width="153" height="60" alt="" src="/upload/2009-11-15/155439_2.jpg" />1、什么是在线编辑器 2、fckeditor配置 3、fckeditor的应用 4、fckeditor结合数据库应用</p>

回答:

<?php
$str ='<p><img alt="" width="153" src="/upload/2009-11-15/9_3.jpg" height="60" /><img src="/upload/2009-11-15/58263668.png" alt="" /><img width="153" height="60" alt="" src="/upload/2009-11-15/155439_2.jpg" />1、什么是在线编辑器 2、fckeditor配置 3、fckeditor的应用 4、fckeditor结合数据库应用</p>';
preg_match_all("/<img.*?src="(.*?)"[^>]*>/i",$str,$match);
print_r($match);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读