- php教程首页
- 正则表达式
php提取文章内容图片地址正则表达式
•正则表达式•阅读 465 - <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="content-type" content="text/html; charset=gb2312" />
- <title>php提取文章内容图片地址正则表达式</title>
- </head>
- <body>
- <form name="form1" method="post" action="">
- <p>
- <label for="body"></label>
- <textarea name="body" cols="45" rows="5"></textarea>
- </p>
- <p>
- <input type="submit" name="button" value="提交" />
- </p>
- </form>
- </body>
- </html>
- <?
- if( $_post )
- {
- $body = $_post['body'];
- preg_match_all("/(src|src)=["|'| ]{0,}((.*).(gif|jpg|jpeg|png|bmp))/isu",$body,$array);
- if( $array )
- {
- echo '取得图片地址';
- print_r($array);
- }
- else
- {
- echo '文章内容中不存在有效的图片地址';
- }
- }
- /*测试 ,输入
- 这里是www.phpfensi.com为你提供一款正则取处文章内容中的图片地址代码如下
- <img src=http://filesimg.phpfensi.com/2010/03/20100811004403298.gif />
- fdsafdsafsa
- 结果:
- 取得图片地址array
- (
- [0] => array
- (
- [0] => src=http://filesimg.phpfensi.com/2010/03/20100811004403298.gif
- )
- [1] => array
- (
- [0] => src
- )
- [2] => array
- (
- [0] => http://filesimg.111cn.net/2010/03/20100811004403298.gif
- )
- [3] => array
- (
- [0] => http://www.phpfensi.com/a
- )
- [4] => array
- (
- [0] => gif
- )
- )
- ?>