国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 黄大仙区| 通化县| 海淀区| 轮台县| 宜宾市| 安塞县| 全州县| 马关县| 昔阳县| 松滋市| 合水县| 黄龙县| 秦皇岛市| 新和县| 宜黄县| 柘荣县| 闽清县| 桂阳县| 德钦县| 拉萨市| 洪洞县| 邯郸县| 稻城县| 登封市| 东乡族自治县| 陵水| 栾川县| 丘北县| 托里县| 桦川县| 红安县| 乐昌市| 郴州市| 布拖县| 南平市| 饶阳县| 永济市| 额济纳旗| 广宁县| 高青县| 南岸区|