首页 > 语言 > PHP > 正文

php提取文章内容图片地址正则表达式

2024-09-04 11:47:31
字体:大 中 小
来源:转载
供稿:网友
  1. <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> 
  2. <html xmlns="http://www.w3.org/1999/xhtml"> 
  3. <head> 
  4. <meta http-equiv="content-type" content="text/html; charset=gb2312" /> 
  5. <title>php提取文章内容图片地址正则表达式</title> 
  6. </head> 
  7.  
  8. <body> 
  9. <form id="form1" name="form1" method="post" action=""> 
  10.   <p> 
  11.     <label for="body"></label> 
  12.     <textarea name="body" id="body" cols="45" rows="5"></textarea> 
  13.   </p> 
  14.   <p> 
  15.     <input type="submit" name="button" id="button" value="提交" /> 
  16.   </p> 
  17. </form> 
  18. </body> 
  19. </html> 
  20. <? 
  21. if( $_post ) 
  22. { 
  23.  $body = $_post['body']; 
  24.  preg_match_all("/(src|src)=["|'| ]{0,}((.*).(gif|jpg|jpeg|png|bmp))/isu",$body,$array);  
  25.  if( $array ) 
  26.  { 
  27.   echo '取得图片地址'; 
  28.   print_r($array); 
  29.  } 
  30.  else 
  31.  { 
  32.   echo '文章内容中不存在有效的图片地址'; 
  33.  } 
  34. } 
  35.  
  36. /*测试 ,输入 
  37. 这里是www.Vevb.com为你提供一款正则取处文章内容中的图片地址代码如下 
  38. <img src=http://filesimg.Vevb.com/2010/03/20100811004403298.gif /> 
  39. fdsafdsafsa 
  40. 结果: 
  41. 取得图片地址array 
  42. ( 
  43.     [0] => array 
  44.         ( 
  45.             [0] => src=http://filesimg.Vevb.com/2010/03/20100811004403298.gif 
  46.         ) 
  47.  
  48.     [1] => array 
  49.         ( 
  50.             [0] => src 
  51.         ) 
  52.  
  53.     [2] => array 
  54.         ( 
  55.             [0] => http://filesimg.111cn.net/2010/03/20100811004403298.gif 
  56.         ) 
  57.  
  58.     [3] => array 
  59.         ( 
  60.             [0] => http://www.Vevb.com/a 
  61.         ) 
  62.  
  63.     [4] => array 
  64.         ( 
  65.             [0] => gif 
  66.         ) 
  67.  
  68. ) 
  69. ?> 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表