I need some function to check is the given value is a url.
I have code:
<?php
$string = get_from_db();
list($name, $url) = explode(": ", $string);
if (is_url($url)) {
$link = array('name' => $name, 'link' => $url);
} else {
$text = $string;
}
// Make some things
?>
If you’re running PHP 5 (and you should be!), just use
filter_var():Addendum: as the PHP manual entry for
parse_url()(and @Liutas in his comment) points out:For example,
parse_url()considers a query string as part of a URL. However, a query string is not entirely a URL. The following line of code:Outputs this: