[eluser]TheFuzzy0ne[/eluser]
Thought I'd share this function with everyone. It actually checks to see if the link is valid.
This version I keep in my own URL helper, and it uses prep_url().
Code:
function is_working_url($url)
{
$url = prep_url($url);
$header_arr = @get_headers($url);
if (is_array($header_arr) && preg_grep('/HTTP\/\d+\.\d+ 200 OK/', $header_arr))
{
return TRUE;
}
return FALSE;
}
This version is a standalone version, which is ideal for those who don't have the URL helper loaded, or don't want to check if it is.
Code:
function is_working_url($url)
{
if (substr($url, 0, 7) != 'http://' && substr($url, 0, 8) != 'https://')
{
$url = 'http://'.$url;
}
$header_arr = @get_headers($url);
if (is_array($header_arr) && preg_grep('/HTTP\/\d+\.\d+ 200 OK/', $header_arr))
{
return TRUE;
}
return FALSE;
}
I find the functions very useful for form validation.