當$url_xxx = www.googlecom
或http://www.5555testetstcom
或http://wwwgooglecom
它會回顯OK
爲什麼?使用php不檢查url格式
<?PHP
$url_xxx = mysqli_real_escape_string($db_mysqli,$_POST['url_xxx']);
if(!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$url_xxx))
{
echo "URL incorrect format";
}
else
{
echo "OK";
}
?>
因爲你的正則表達式是無效的?你爲什麼要在主機上檢查'[-a-z0-9 +&@#\ /%=〜_ |]'? – Devon
如何使用parse_url'http:// php.net/manual/en/function.parse-url.php'來檢查url的部分。然後,如果需要,只用正則表達式檢查零件。 – JustOnUnderMillions
你可以請我舉個例子嗎? –