當前位置:首頁 » 編程語言 » php正則鏈接

php正則鏈接

發布時間: 2022-06-23 10:50:00

1. php怎麼用正則判斷文章中是否有超鏈接

$pos = strpos($text,'</a>');
if ($pos === false) {
echo "恭喜,沒有超鏈接";
}else{
echo "包含超鏈接";
}
比正則表達式快。正則表達式一般用來解析內容才用。

2. PHP正則鏈接帶有&符號就無效

$a='v.swf&topBar=1&id=81144212&autoplay=false&from=page';
if(preg_match('|id\=(?<id>[^&]+)|i',$a,$match)){
var_mp($match['id']);
}

3. php正則表達式提取鏈接

$preg='/<a .*?href="(.*?)".*?>/is';
$str ='<a href="鏈接">123</a><a href="鏈接" target="_blank">345</a><a target="_blank" href="鏈接">678</a>';
preg_match_all($preg,$str,$match);
var_mp($match);

4. php 正則 <a ></a> 中的 href 和img 地址

針對給定的標本數據,編寫如下正則供參考:

1、提取 jpg 地址鏈接

"(http://.*?.jpg)"



2、提取 a href 或是 img src 標簽中的 jpg 地址鏈接

[href|src]="(http://.*?.jpg)"


3、提取<a></a>標簽中的 jpg 地址鏈接

(<a.*)(http://.*.jpg)(".*")(http:/.*.jpg)(".*)</a>

5. php正則獲取href的鏈接

使用正則中的子模式,按給出的代碼匹配的話大概是這樣

$pattern='/href="([^(}>)]+)"/';

然後使用preg_match或者preg_match_all如果替換的話使用preg_replace即可

6. php 取超鏈接的正則表達式

這段代碼應該是你想要的.
==========
<?php

$test =<<<EOF
<a class="t4" href="read.php?id=9576" title="ffff">********</a>
@@@@@@@@@@@@@@
<a class="t5" href="read.php?id=9576" title="ffff">@@@@@@@</a>
EOF;
$pattern = '/href="(.*?)"/';
preg_match_all($pattern,$test,$result);
//你要的結果在數組的第二個元素內.
//print_r($result);
foreach($result[1] as $ritem){
echo $ritem;
}
?>

7. php匹配html中這幾段鏈接的正則表達式

<?php
$s=<<<STR
"index.html?s=/Home/Article/content/id/20"
"index.html?s=/Home/Article/content/id/21"
"index.html?s=/Home/Article/content/id/22"
"index.html?s=/Home/Article/content/id/999"
STR;

preg_match_all('~"(.*d+)"~',$s,$m);

print_r($m[1]);

8. php正則表達式去除超鏈接。

preg_replace正則匹配,去除所有a鏈接地址,並且保留裡面a裡面的內容
preg_replace(「#<a[^>]*>(.*?)</a>#is」, 「$1」,$body);
ereg_replace正則匹配:
ereg_replace(「]*>|</a>」,」」,$content);
ereg_replace函數匹配以」<a 「開頭,中間除>以外的所有字元,再以>結尾的字元串或匹配」」字元。匹配到的字元串賦為空。

9. php高手請進:正則提取超鏈接中的網址和標題,如果兼顧有雙引號和單引號或沒有引號的超鏈接

<?php

$text = "遞歸是一種函數調用自身的機制。這是一種強大的特性可以把某些復雜的東西變得很簡單。<a href='http://mp3..com'>MP1</a><a href=http://mp3..com>MP2</a><a href='http://mp3..com' target='_blank'>MP3</a><a href=http://mp3..com target=mainFrame>MP4</a><a href=http://mp3..com style=\"font-size:32px;color:#e53333;\">MP5</a><a href=\"http://mp3..com\">MP6</a>";
preg_match_all('/<a href=(.*)>(.*)<\/a>/isU',$text,$data_arr);

foreach( $data_arr[1] as $key=>$val ) {

$replace_str = $data_arr[0][$key];
$title = $data_arr[2][$key];
preg_match("/(https?|ftp|mms):\/\/([A-z0-9]+[_\-]?[A-z0-9]+\.)*[A-z0-9]+\-?[A-z0-9]+\.[A-z]{2,}(\/.*)*\/?/",$val,$url_data);
$url = $url_data[0];
$text = str_replace($replace_str,"<br/>\n{$title} {$url}",$text);

}

var_mp($text);

?>

這個可以識別得了網址中包含http開頭的鏈接地址格式的。但如果還需匹配相對地址,建議是將所有可能出現的情況一一替換掉

10. PHP 正則表達式 獲取字元串 所有鏈接

你這個也會報錯 菜雞

熱點內容
演算法牛人左 發布:2025-02-05 15:31:02 瀏覽:438
php篩選功能 發布:2025-02-05 15:29:09 瀏覽:166
ip匹配伺服器 發布:2025-02-05 15:10:35 瀏覽:909
php語法後 發布:2025-02-05 15:10:34 瀏覽:59
oppor9s怎麼壓縮文件 發布:2025-02-05 15:00:34 瀏覽:639
蘋果耳塞怎麼改安卓也能用 發布:2025-02-05 14:50:54 瀏覽:558
安卓如何鑒別手機真假 發布:2025-02-05 14:28:15 瀏覽:121
ffmpeglinux編譯 發布:2025-02-05 14:28:04 瀏覽:545
伺服器如何做界面 發布:2025-02-05 14:27:23 瀏覽:291
訪問學者單位推薦意見 發布:2025-02-05 14:13:05 瀏覽:854