php微信公眾平臺示例代碼分析(二)
688
2024-01-19
本文實例講述了PHP正則匹配操作。分享給大家供大家參考,具體如下:
<?php $str = <<< EOT <a rel="external nofollow" > <div class="phonebg"> <img src="http://www/template9/yunqingjian/jianjie/68.jpg" > <div class="phoneclick"></div> <p>幸福領地</p> </div> </a> <a rel="external nofollow" > <div class="phonebg"> <img src="http://www/template9/yunqingjian/jianjie/69.jpg" > <div class="phoneclick"></div> <p>一世情長</p> </div> </a> EOT; if(preg_match_all('%<p.*?>(.*?)</p>%si', $str, $matches)) { $arr[0][] = $matches[1]; } if(preg_match_all('/src="http://www.gimoo.net/t/1801/([^<]*)" >/i', $str, $matches)) { $arr[1][] = $matches[1]; } print_r($arr); exit; ?>
運行結果如下:
Array ( [0] => Array ( [0] => Array ( [0] => 幸福領地 [1] => 一世情長 ) ) [1] => Array ( [0] => Array ( [0] => http://www/template9/yunqingjian/jianjie/68.jpg [1] => http://www/template9/yunqingjian/jianjie/69.jpg ) ) )
PS:這里再為大家提供2款非常方便的正則表達式工具供大家參考使用:
JavaScript正則表達式在線測試工具:
http://tools.gimoo.net/regex/javascript
正則表達式在線生成工具:
http://tools.gimoo.net/regex/create_reg
更多關于PHP相關內容感興趣的讀者可查看本站專題:《php正則表達式用法總結》、《PHP數組(Array)操作技巧大全》、《PHP基本語法入門教程》、《php字符串(string)用法總結》、《php+mysql數據庫操作入門教程》及《php常見數據庫操作技巧匯總》
希望本文所述對大家PHP程序設計有所幫助。
#免責聲明#
本站[綠夏技術導航]提供的一切軟件、教程和內容信息僅限用于學習和研究目的;不得將上述內容用于商業或者非法用途,否則,一切后果請用戶自負。本站信息來自網絡收集整理,版權爭議與本站無關。您必須在下載后的24個小時之內,從您的電腦或手機中徹底刪除上述內容。如果您喜歡該程序或內容,請支持正版,購買注冊,得到更好的正版服務。我們非常重視版權問題,如有侵權請郵件[admin@lxwl520.com]與我們聯系進行刪除處理。敬請諒解!