urlencode()函数原理就是首先把中文字符转换为十六进制,然后在每个字符前面加一个标识符%,对字符串中除了 -_. 之外的所有非字母数字字符都将被替换成百分号(%)后跟两位十六进制数,空格则编码为加号(+)。
urldecode()函数与urlencode()函数原理相反,用于解码已编码的 URL 字符串,其原理就是把十六进制字符串转换为中文字符。
例如:
index.html
<?php
header("Content-Type:text/html;charset=utf-8");
$parm=urlencode("演示PHP-MYSQL");
$url="index.php?par=".$parm;
?>
<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Strict//EN' 'http://www.w3.org/TR/html4/strict.dtd'>
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
<title>insert into title</title>
</head>
<body>
<a href="<?php echo $url;?>">urlencode演示</a>
</body>
</html>
url输出结果:http://localhost/namespace2/space2/index3.php?par=%E6%BC%94%E7%A4%BAPHP-MYSQL
index.php
$parValue=$_GET['par'];
echo urldecode($parValue);
OutPut: 演示PHP-MYSQL
下面这个链接也是介绍这一块的:
https://www.cnblogs.com/wpclw/p/6141793.html
本文介绍了URL编码(urlencode)和解码(urldecode)的工作原理,urlencode将特殊字符转换为适用于URL的形式,urldecode则执行逆操作。通过实例展示了如何使用PHP实现这两个功能。
372

被折叠的 条评论
为什么被折叠?



