Php 用于检查URL是否位于特定域下的正则表达式
我需要一个正则表达式,它可以发现给定的URL是否在我的网站下 例如:Php 用于检查URL是否位于特定域下的正则表达式,php,regex,preg-match,Php,Regex,Preg Match,我需要一个正则表达式,它可以发现给定的URL是否在我的网站下 例如: http://www.my_domain.com/internal_page should give true. www.my_domain.com/internal_page should give false. http://www.my_domain.com should give false. ( should have a "/" after .com ). http://www.my_domain.com:dfd
http://www.my_domain.com/internal_page should give true.
www.my_domain.com/internal_page should give false.
http://www.my_domain.com should give false. ( should have a "/" after .com ).
http://www.my_domain.com:dfdf should give false.
--
谢谢这个怎么样
http:\/\/www\.my_domain\.com\/(.+)
它通过了您提供的四项测试您可以这样做
$url = "http://www.my_domain.com/internal_page";
$host = "www.my_domain.com";
if(strpos($url, "http://".$host."/") === 0){
// we have a winner
} else {
// no good
}
下面是您想要的模式
$pattern = "#^https?://www.my_domain\.com(/.*)?$#";
$test = 'http://www.google.com';
if ( preg_match( $pattern, $test ) )
{
echo $test, " <strong>matched!</strong><br>";
} else {
echo $test, " <strong>did not match.</strong><br>";
}
$pattern=“#^https?://www.my_domain\.com(/.*)?$”;
$test='1http://www.google.com';
if(预匹配($pattern$test))
{
echo$test,“匹配!
”;
}否则{
echo$test,“不匹配。
”;
}
使用此
http:\/\/www\.my_domain\.com\/.*
你应该在发帖前表现出一些努力
-表示http://http:\/\/
等于www.mydomain.comwww\.myu domain\.com
表示/和0或表达式结尾的任何字符\/.