如何用PHP正则表达式实现几乎全范围的网址匹配?
- 内容介绍
- 文章标签
- 相关推荐
本文共计327个文字,预计阅读时间需要2分钟。
比较简单的正则表达式如下:
php$pattern='/^(https?|ftp|rtsp|mms):\/\/[^\s]+$/';$testStr='http://example.com';$matches=[];
if (preg_match($pattern, $testStr, $matches)) { echo 匹配成功:; print_r($matches);} else { echo 匹配失败;}
该表达式可以匹配以http、https、ftp、rtsp或mms开头的网址。
比较简单的
$str = ''; $isMatched = preg_match('/^^((https|http|ftp|rtsp|mms)?:\/\/)[^\s]+$/', $str, $matches); var_dump($isMatched, $matches);
几乎可以匹配任何网址:
^((https?|ftp|news):\/\/)?([a-z]([a-z0-9\-]*[\.。
本文共计327个文字,预计阅读时间需要2分钟。
比较简单的正则表达式如下:
php$pattern='/^(https?|ftp|rtsp|mms):\/\/[^\s]+$/';$testStr='http://example.com';$matches=[];
if (preg_match($pattern, $testStr, $matches)) { echo 匹配成功:; print_r($matches);} else { echo 匹配失败;}
该表达式可以匹配以http、https、ftp、rtsp或mms开头的网址。
比较简单的
$str = ''; $isMatched = preg_match('/^^((https|http|ftp|rtsp|mms)?:\/\/)[^\s]+$/', $str, $matches); var_dump($isMatched, $matches);
几乎可以匹配任何网址:
^((https?|ftp|news):\/\/)?([a-z]([a-z0-9\-]*[\.。

