I need a complete URL regex. In other words, I need a script that verifies whether or not a URL is valid. Ex. http://www.domain.com is valid http://www.$#.com is not valid Any help is appreciated. I googled it but have had no luck so far... the ones I found were incomplete or not working. Thanks!
Simply way would be to check whether the site is online or not ! All the invalid urls would not be online,so you can use this code $url="http://www.google.com"; $url1=@file_get_contents($url); if(!($url1)) { echo"Invalid url"; } { echo"Valid url"; } PHP:
Don't use file_get_contents(). It's slow and takes a lot of memory. If you want to go this way at all, use get_headers().
Hi, Theres plenty of different email checking methods on google - Quick search came up with the following explaining email validation (using regular expressions) www.addedbytes.com/php/email-address-validation Hope it helps, Regards, Steve
This simple regexp: $pat = '~[url]http://www\[/url].[a-z0-9_-]+\.[a-z\.]{2,5}~i'; $url = 'http://www.domain.com'; if(preg_match($pat,$url)) { .......... ..valid url..... }else{ ... not valid ..... } Code (markup):
use $url = "www.google.com"; $newurl = preg_repace('/www\./'.'//',$url); echo $newurl; something like that
Use filter_var to validate an URL (not to check if it exists but if it's correctly writen). http://nl2.php.net/filter_var http://nl2.php.net/manual/en/filter.constants.php
Wow ) I did not know this. Yes, better use this: $url = 'http://www.domain.com'; if(filter_var($url,FILTER_VALIDATE_URL)) { ......... ..valid url..... }else{ ... not valid ..... }