Hello i tried to prevent insert url in string like this:
function containsURL($string) {
//check if string contains url
$remove = array(" ", "!", ",", "@", "#", "$", "%", "^", "&", "*", "(", ")");
$string = str_replace($remove, "", $string);
$regex = "((https?|ftp)\:\/\/)?"; // SCHEME
$regex .= "([a-z0-9+!*(),;?&=\$_.-]+(\:[a-z0-9+!*(),;?&=\$_.-]+)?@)?"; // User and Pass
$regex .= "([a-z0-9-.]*)\.([a-z]{2,3})"; // Host or IP
$regex .= "(\:[0-9]{2,5})?"; // Port
$regex .= "(\/([a-z0-9+\$_-]\.?)+)*\/?"; // Path
$regex .= "(\?[a-z+&\$_.-][a-z0-9;:@&%=+\/\$_.-]*)?"; // GET Query
$regex .= "(#[a-z_.-][a-z0-9+\$_.-]*)?"; // Anchor
if(preg_match("/^{$regex}$/", $string)) //contains
return true;
return false;
}
but its not prevent everything urls like this:
bit.ly/18SuUzJ (with http)
its not prevent or like this
bit.ly/18SuUzJ (without http)
or other url shorter generators...
but i need to do? tnx