PHP正则取得所有图片的路径
发布时间:2015-10-14, 15:45:54 分类:PHP | 编辑 off 网址 | 辅助
正文 2223字数 134,604阅读
问题:
如下面内容,两个问题:
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>
Run code
Cut to clipboard
回答:
<?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);
Run code
Cut to clipboard
<?php
//dump($content);
$str=$content;
$pattern="/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg]))[\'|\"].*?[\/]?>/";
preg_match_all($pattern,$str,$match);
//print_r($match ['1']);
$pic_arr_n=count($match['1']);
$pic_arr_n_i=0;
$pattern="/<[img|IMG].*?title=[\'|\"](.*?)[\'|\"].*?[\/]?>/";
//preg_match_all('/<img.+(title=/"?/d*/"?).+>/i',$str,$matchsrc);
preg_match_all($pattern,$str,$matchsrc);
//print_r($matchsrc['1']);
//$pic_arr_n=count($match['1']);
//$pic_arr_n_i=0;
?>
Run code
Cut to clipboard
(支付宝)给作者钱财以资鼓励 (微信)→
暂无评论 »