public static function safeUrl($url)
    {
        // Strip invalid characters (anything but [a-zA-Z0-9=?&:;#_\/.-])
//        $url = preg_replace("/[^a-zA-Z0-9=?&:;#_\/.-]/", '', $url);

        if (empty($url))
            return '';

        // Prepend http:// if no scheme is specified
        if (!preg_match("/^(https?):\/\//", $url))
            $url = 'http://' . $url;

        if (!self::isURL($url))
            $url = '';

        return filter_var($url,  FILTER_SANITIZE_URL);

    }
public static function safeUrl($url)
    {
        // Strip invalid characters (anything but [a-zA-Z0-9=?&:;#_\/.-])
//        $url = preg_replace("/[^a-zA-Z0-9=?&:;#_\/.-]/", '', $url);

        if (empty($url))
            return '';

        // Prepend http:// if no scheme is specified
        if (!preg_match("/^(https?):\/\//", $url))
            $url = 'http://' . $url;

        if (!self::isURL($url))
            $url = '';

        return filter_var($url,  FILTER_SANITIZE_URL);

    }
public static function safeUrl ( $ url ) { // Strip invalid characters (anything but [a-zA-Z0-9=?&:;#_\/.-]) //        $url = preg_replace("/[^a-zA-Z0-9=?&:;#_\/.-]/", '', $url); if ( empty ( $ url ) ) return '' ; // Prepend http:// if no scheme is specified if ( ! preg_match ( "/^(https?):\/\//" , $ url ) ) $ url = 'http://' . $ url ; if ( ! self :: isURL ( $ url ) ) $ url = '' ; return filter_var ( $ url , FILTER_SANITIZE_URL ) ; }
Outputs a "safe" url, stripped of xss, autolink on domain, and stripped of invalid chars

@param string $url The url to process

@return string Safe and happy URL
Outputs a safe url stripped of xss autolink on domain and stripped of invalid chars