- <!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 id="form1" name="form1" method="post" action="">
- <p>
- <label for="body"></label>
- <textarea name="body" id="body" cols="45" rows="5"></textarea>
- </p>
- <p>
- <input type="submit" name="button" id="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.49028c.com為你提供一款正則取處文章內容中的圖片地址代碼如下
- <img src=http://filesimg.Vevb.com/2010/03/20100811004403298.gif />
- fdsafdsafsa
- 結果:
- 取得圖片地址array
- (
- [0] => array
- (
- [0] => src=http://filesimg.Vevb.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.49028c.com/a
- )
- [4] => array
- (
- [0] => gif
- )
- )
- ?>
新聞熱點
疑難解答