<?php
$url =”http://x.com“;
echo urlencode($url); //输出编码后的字符串
?>
<?php
$url = “http://x.com“;
$newurl = urlencode($url); //首先对$url进行编码
echo urldecode($newurl); //输出解码后的字符串
?>
urlencode
将字串以 URL 编码。
语法: string urlencode(string str);
传回值: 字串
函式种类: 编码处理
内容说明
本函式将字串以 URL 编码。例如空格就会变成加号。Homepage 中 form 资料传送就是用 urlencode 编码后再送出。
使用范例
本例将中文字串以 URL 编码过,转给别的 CGI 使用
$EncodeStr=urlencode($ChineseName);
echo "个人资讯";
?>
=============================================================
urldecode
还原 URL 编码字串。
语法: string urldecode(string str);
传回值: 字串
函式种类: 编码处理
内容说明
本函式将 URL 编码后字串还原成未编码的样子。编码使用 %## 的格式。
rawurlencode
还原 URL 编码字串。
语法: string rawurlencode(string str);
传回值: 字串
函式种类: 编码处理
内容说明
本函式将字串以 URL 编码。例如空格就会变成 %20 。Homepage 中 form 资料传送就是用 urlencode 编码后再送出。
使用范例
本例将中文字串以 URL 编码过,转给别的 CGI 使用
$EncodeStr=urlencode($ChineseName);
echo "个人资讯";
?>
string rawurldecode(string str);本函式将字串编码成 URL 的字串专用格式,特殊的字元会转换成百分比符号后面加上二个十六位元数字的格式。例如,空格就会变成 %20;
string urlencode(string str);本函式将字串以 URL 编码。例如空格就会变成加号。Homepage 中 form 资料传送就是用 urlencode 编码后再送出。
foo是用户自己定义的,做函数的时候是用户自己定义的函数,作变量也是用户自己的,你可以改成任何你喜欢的名字,比如haha