时间:2021-07-01 10:21:17 帮助过:18人阅读
$pattern = '/(http\:\/\/|https\:\/\/)?([a-zA-Z0-9-]+\.)+(com|cn|org|net)(\/[\w\%\&\=\'\"\?\/\.]*)?/';
$string = 'http://demo.demo.baidu.com';
preg_match_all($pattern,$string,$result);
(http\:\/\/
------解决方案--------------------
https\:\/\/)?(([a-zA-Z0-9-]+\.)+)+(com
------解决方案--------------------
cn
------解决方案--------------------
org
------解决方案--------------------
net)(\/[\w\%\&\=\'\"\?\/\.]*)?
$pattern = '/(http\:\/\/
------解决方案--------------------
https\:\/\/)?((?:[a-zA-Z0-9-]+\.)+)(com
------解决方案--------------------
cn
------解决方案--------------------
org
------解决方案--------------------
net)(\/[\w%&=\'"?\/.]*)?/';
$string = 'http://demo.demo.baidu.com';
preg_match_all($pattern,$string,$result);
Array
(
[0] => Array
(
[0] => http://demo.demo.baidu.com
)
[1] => Array
(
[0] => http://
)
[2] => Array
(
[0] => demo.demo.baidu.
)
[3] => Array
(
[0] => com
)
[4] => Array
(
[0] =>
)
)