网址判断的,只要是网址就匹配。你能为空、必须以http://、https://和ftp://开头。我写的老是不行....先谢谢啦
网址判断的,只要是网址就匹配。你能为空、必须以http://、https://和ftp://开头。我写的老是不行....先谢谢啦
æ£å表达å¼å¦ä¸ï¼
'/\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>';
?>
'/\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>';
?>
温馨提示:答案为网友推荐,仅供参考
第1个回答 2012-08-04
《php获取页面所有链接的正则表达式》,搜一下,仅供参考!本回答被网友采纳