本文目錄一覽:
php正則獲取href的鏈接
使用正則中的子模式,按給出的代碼匹配的話大概是這樣
$pattern=’/href=\”([^(\})]+)\”/’;
然後使用preg_match或者preg_match_all如果替換的話使用preg_replace即可
php正則表達式去除超鏈接。
preg_replace正則匹配,去除所有a鏈接地址,並且保留裡面a裡面的內容
preg_replace(“#a[^]*(.*?)/a#is”, “$1”,$body);
ereg_replace正則匹配:
ereg_replace(“]*|/a”,””,$content);
ereg_replace函數匹配以”a “開頭,中間除以外的所有字符,再以結尾的字符串或匹配””字符。匹配到的字符串賦為空。
php正則表達式提取鏈接
$preg=’/a .*?href=”(.*?)”.*?/is’;
$str =’a href=”鏈接”123/aa href=”鏈接” target=”_blank”345/aa target=”_blank” href=”鏈接”678/a’;
preg_match_all($preg,$str,$match);
var_dump($match);
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/151156.html