PHP正则表达式求助。

网址判断的,只要是网址就匹配。你能为空、必须以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>';
?>
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-08-04
《php获取页面所有链接的正则表达式》,搜一下,仅供参考!本回答被网友采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网