M marcel Established Member ★ 20 ★ Impact 3 Jan 6, 2006 2K views 3 replies #1 how do I parse a URL in PHP ? I want to make sure the link is a real website. any known classes for this ?
how do I parse a URL in PHP ? I want to make sure the link is a real website. any known classes for this ?
M mch Established Member ★ 20 ★ Impact 2 Jan 7, 2006 #2 Try this buddy: PHP: if (preg_match("/http(s?):\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/\?%&=]*)?/i", $url_to_parse)) { //URL is valid, do stuff } Regex pattern taken from: http://objectsharp.com/blogs/dave/archive/2004/05/17/446.aspx
Try this buddy: PHP: if (preg_match("/http(s?):\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/\?%&=]*)?/i", $url_to_parse)) { //URL is valid, do stuff } Regex pattern taken from: http://objectsharp.com/blogs/dave/archive/2004/05/17/446.aspx
eli03 VIP Member VIP ★ 20 ★ Impact 20 Jan 12, 2006 #3 you can also add this function, to know if the site is existing PHP: function if_url_exist($url) { $fp = @fopen($url,"r"); if ($fp) { fclose($fp); $ret ="Y"; } else { $ret ="N"; } return $ret; } //test $url="http://www.bigvertiser.com"; $test = if_url_exist($url); echo $test;
you can also add this function, to know if the site is existing PHP: function if_url_exist($url) { $fp = @fopen($url,"r"); if ($fp) { fclose($fp); $ret ="Y"; } else { $ret ="N"; } return $ret; } //test $url="http://www.bigvertiser.com"; $test = if_url_exist($url); echo $test;