我认为 filter_var 在我的不同服务器上的工作方式不同,这是我正在运行的代码:
$url = "http://www.my-domain.com";
$urlOriginal = "http://www.my-domain.com";
$url = filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED | FILTER_FLAG_HOST_REQUIRED);
echo $url;
echo "<br/>Php version: " . phpversion();
echo "<br/><h1>";
if ($url == $urlOriginal){
echo "it worked because $url == $urlOriginal";
} else {
echo "it didn't work, because $url != $urlOriginal";
}
echo "</h1>";
一台服务器上的输出是
http://www.my-domain.com
Php version: 5.2.13
it worked because http://www.my-domain.com == http://www.my-domain.com
另一方面是
Php version: 5.2.13
it didn't work, because != http://www.my-domain.com
由于他们都使用相同版本的 PHP,我认为这可能与配置方式有关,知道那是什么吗?
我还发现这可能是相关的: https ://bugs.php.net/bug.php?id=51305&edit=1