Home > Backend Development > PHP Tutorial > 为啥提交得出的rawurlencode() 跟直接输出的不一样的呢

为啥提交得出的rawurlencode() 跟直接输出的不一样的呢

WBOY
Release: 2016-06-13 10:34:29
Original
807 people have browsed it

为什么提交得出的rawurlencode() 跟直接输出的不一样的呢?
 
if($_POST['submit']){ 
echo $_POST['name']."=
"; 
echo rawurlencode($_POST['name']); 

echo rawurlencode("女人"); 
?> 





这样提交“女人”得出:%C5%AE%C8%CB
而直接输出的 rawurlencode("女人"): 又是:%E5%A5%B3%E4%BA%BA

这是为什么呢?


------解决方案--------------------
因为提交的是gbk,你的php文件是utf8.
------解决方案--------------------
另外提醒, 表单提交来的是urlencode,不是rawurlencode,而JS的URIcomponentEncode(是不是这么拼)相当于php的rawurlencode,主要区别就是空格是+还是%20.

你想看到正确结果如下:

PHP code
<?phpecho iconv("gbk", "utf8", urldecode("%C5%AE%C8%CB"));echo urldecode("%E5%A5%B3%E4%BA%BA");?><div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template