国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > PHP > 正文

php正則表達式提取圖片地址 超鏈接 標題 實現(xiàn)代碼

2024-09-04 11:47:10
字體:
來源:轉載
供稿:網(wǎng)友

正則表達式提取網(wǎng)址中的id,代碼如下:

  1. preg_match('/http://t.sina.com.cn/(d+)/fans//',$html,$result); //正則表達式提取網(wǎng)址中的id 
  2. echo $result[1]; 

PHP的正則表達式提取圖片地址的代碼,代碼如下:

  1. $str='<p style="padding: 0px; margin-top: 0px; margin-bottom: 0px; line-height: 200%;"><img border="0" src="upfiles/2009/07/1246430143_4.jpg" alt=""/></p><p style="padding: 0px; margin-top: 0px; margin-bottom: 0px; line-height: 200%;"><img border="0" src="upfiles/2009/07/1246430143_3.jpg" alt=""/></p><p style="padding: 0px; margin-top: 0px; margin-bottom: 0px; line-height: 200%;"><img border="0" src="upfiles/2009/07/1246430143_1.jpg" alt=""/></p>';  $pattern="/<[img|IMG].*?src=['|"](.*?(?:[.gif|.jpg]))['|"].*?[/]?>/";  preg_match_all($pattern,$str,$match);  print_r($match); 

PHP正則表達式提取超鏈接及其標題,代碼如下:

  1. $str = '<a id="top8" href="http://list.MP3.baidu.com/song/A.htm?top8" class="p14" target="_top">歌曲列表</a><br><a target="_blank" id="bp" href="http://list.mp3.baidu.com/list/bangping.html" class="p14">中文金曲榜</a><br><td nowrap="nowrap">&#8226;&nbsp;<a id="top19" href="qingyinyue.html?top19" class="p14" target="_top">輕音樂</a></td>'
  2. 利用正則表達式是最簡單的,其它的辦法,偶米去想。。。 
  3. $pat = '/<a(.*?)href="(.*?)"(.*?)>(.*?)</a>/i'
  4. preg_match_all($pat$str$m); 

輸出方法:print_r($m[2]);print_r($m[4]);

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 洪雅县| 垦利县| 布尔津县| 惠水县| 葫芦岛市| 突泉县| 宽城| 泸溪县| 辽源市| 贵德县| 闸北区| 泗水县| 同德县| 营口市| 呼玛县| 黎城县| 壶关县| 阿坝县| 苍山县| 睢宁县| 万宁市| 林口县| 紫阳县| 乐安县| 都兰县| 论坛| 三门县| 凤凰县| 勐海县| 阿瓦提县| 含山县| 扬中市| 东乌珠穆沁旗| 伊宁市| 永靖县| 新田县| 昭苏县| 兴安盟| 友谊县| 神农架林区| 巢湖市|