问题:http://www.
和.com
OR http://
& .com
之间提取任何东西。校正获得网站名称
解决方案:
<?php
$url1='http://www.examplehotel.com';
//$url2='http://test-hotel-1.com';
$pattern='@^http://([^/]+)[email protected]';
preg_match($pattern, $url1, $matches);
print_r($matches);
?>
当$ URL1匹配,它应该返回字符串 'examplehotel'
当$ URL2匹配,它应该返回字符串 '测试酒店-1'
它正常工作为$ URL2但为空URL1 $ ....
在我的模式我想补充[http://]
或[http://www.]
我加(http://)+(www.)+
但是匹配的回报也无法教人口会d :(。
我可以知道我要去哪里吗?
+1这明显帮助我了解我错在哪里。感谢Stema – user269867