As I wasted lots of time finding a REAL regex for URLs and resulted in building it on my own, I now have found one, that seems to work for all kinds of urls:
<?php
$regex = "((https?|ftp)\:\/\/)?"; $regex .= "([a-z0-9+!*(),;?&=\$_.-]+(\:[a-z0-9+!*(),;?&=\$_.-]+)?@)?"; $regex .= "([a-z0-9-.]*)\.([a-z]{2,3})"; $regex .= "(\:[0-9]{2,5})?"; $regex .= "(\/([a-z0-9+\$_-]\.?)+)*\/?"; $regex .= "(\?[a-z+&\$_.-][a-z0-9;:@&%=+\/\$_.-]*)?"; $regex .= "(#[a-z_.-][a-z0-9+\$_.-]*)?"; ?>
Then, the correct way to check against the regex ist as follows:
<?php
if(preg_match("/^$regex$/", $url))
{
return true;
}
?>