URL中用到的一些编码方式

来源:互联网 发布:overture for mac 编辑:程序博客网 时间:2024/04/29 12:52
看到项目代码中有这样一些方法:urlencode, base64_encode, htmlentities等。

网上找了一些资料如下:
string urlencode ( string $str )
    This function is convenient when encoding a string to be used in a query part of a URL, as a convenient way to pass variables to the next page.
    在页面间传递数据时可以使用到该方法。
它的返回值:
    Returns a string in which all non-alphanumeric characters except -_. have been replaced with a percent (%) sign followed by two hex digits and spaces encoded as plus (+) signs. It is encoded the same way that the posted data from a WWW form is encoded, that is the same way as in application/x-www-form-urlencoded media type. This differs from the » RFC 1738 encoding (see rawurlencode()) in that for historical reasons, spaces are encoded as plus (+) signs.
    非文字、且不是-_.的,会被编码为百分号(%)打头的两位16进制数,空格被编码为加号。比如:"browse.myspace.cn/;:"被解析为"browse.myspace.cn%2F%3B%3A"。其中的/;:都被编码了。

string htmlentities ( string $string [, int $quote_style [, string $charset [, bool $double_encode ]]] )   
    This function is identical to htmlspecialchars() in all ways, except with htmlentities(), all characters which have HTML character entity equivalents are translated into these entities.
    If you're wanting to decode instead (the reverse) you can use html_entity_decode().

See Also


string base64_encode ( string $data )
   

Encodes the given data with base64.

This encoding is designed to make binary data survive transport through transport layers that are not 8-bit clean, such as mail bodies.

Base64-encoded data takes about 33% more space than the original data.

一种编码方式,需要占用更多的空间。



在我们的项目中,为了获取一个url,用来供未登陆者,先登陆再返回当前页面使用,其中return_url指向当前页面。

$url = $ms_login_url_prefix;
    $url .= "?t=".urlencode(base64_encode($return_url));
    $k = md5($return_url.$ms_login_secret_key);
    $url .= "&k=".urlencode($k);




原创粉丝点击