protected static function encode_url($url)
    {
        $reserved = array(
            ':' => '!%3A!ui',
            '/' => '!%2F!ui',
            '?' => '!%3F!ui',
            '#' => '!%23!ui',
            '[' => '!%5B!ui',
            ']' => '!%5D!ui',
            '@' => '!%40!ui',
            '!' => '!%21!ui',
            '$' => '!%24!ui',
            '&' => '!%26!ui',
            "'" => '!%27!ui',
            '(' => '!%28!ui',
            ')' => '!%29!ui',
            '*' => '!%2A!ui',
            '+' => '!%2B!ui',
            ',' => '!%2C!ui',
            ';' => '!%3B!ui',
            '=' => '!%3D!ui',
            '%' => '!%25!ui'
        );
        $url = preg_replace(array_values($reserved), array_keys($reserved), rawurlencode($url));
        return $url;
    }
protected static function encode_url($url)
    {
        $reserved = array(
            ':' => '!%3A!ui',
            '/' => '!%2F!ui',
            '?' => '!%3F!ui',
            '#' => '!%23!ui',
            '[' => '!%5B!ui',
            ']' => '!%5D!ui',
            '@' => '!%40!ui',
            '!' => '!%21!ui',
            '$' => '!%24!ui',
            '&' => '!%26!ui',
            "'" => '!%27!ui',
            '(' => '!%28!ui',
            ')' => '!%29!ui',
            '*' => '!%2A!ui',
            '+' => '!%2B!ui',
            ',' => '!%2C!ui',
            ';' => '!%3B!ui',
            '=' => '!%3D!ui',
            '%' => '!%25!ui'
        );
        $url = preg_replace(array_values($reserved), array_keys($reserved), rawurlencode($url));
        return $url;
    }
protected static function encode_url ( $ url ) { $ reserved = array ( ':' => '!%3A!ui' , '/' => '!%2F!ui' , '?' => '!%3F!ui' , '#' => '!%23!ui' , '[' => '!%5B!ui' , ']' => '!%5D!ui' , '@' => '!%40!ui' , '!' => '!%21!ui' , '$' => '!%24!ui' , '&' => '!%26!ui' , "'" => '!%27!ui' , '(' => '!%28!ui' , ')' => '!%29!ui' , '*' => '!%2A!ui' , '+' => '!%2B!ui' , ',' => '!%2C!ui' , ';' => '!%3B!ui' , '=' => '!%3D!ui' , '%' => '!%25!ui' ) ; $ url = preg_replace ( array_values ( $ reserved ) , array_keys ( $ reserved ) , rawurlencode ( $ url ) ) ; return $ url ; }
URL encoder according to RFC 3986
Returns a string containing the encoded URL with disallowed characters converted to their percentage encodings.

@link http://publicmind.in/blog/url-encoding/

@param  string $url
@return string string
URL encoder according to RFC 3986 Returns a string containing the encoded URL with disallowed characters converted to their percentage encodings .