PHP正则表达式求助。
发布网友
发布时间:2022-09-20 01:16
我来回答
共2个回答
热心网友
时间:2023-11-01 12:41
正则表达式如下:
'/\b((?#protocol)https?|ftp):\/\/((?#domain)[-A-Z0-9.]+)((?#file)\/[-A-Z0-9+&@#\/%=~_|!:,.;]*)?((?#parameters)\?[A-Z0-9+&@#\/%=~_|!:,.;]*)?/i'
测试代码:
<?php
$testurl=<<<TTTTT
http://www.regexbuddy.com
ftp://www.regexbuddy.com/
http://www.regexbuddy.com/index.html
http://www.regexbuddy.com/index.html?source=library
You can download RegexBuddy at https://www.regexbuddy.com/download.html
TTTTT;
$pa = '/\b((?#protocol)https?|ftp):\/\/((?#domain)[-A-Z0-9.]+)((?#file)\/[-A-Z0-9+&@#\/%=~_|!:,.;]*)?((?#parameters)\?[A-Z0-9+&@#\/%=~_|!:,.;]*)?/i';
preg_match_all($pa,$testurl,$arr);
echo '<pre>';
print_r($arr);
echo '</pre>';
?>
热心网友
时间:2023-11-01 12:42
《php获取页面所有链接的正则表达式》,搜一下,仅供参考!