[英]PHP Url Encoding Not Encoding Properly
I am trying to encode the following string: Peôn
我正在尝试编码以下字符串:
Peôn
Accordiing to: http://meyerweb.com/eric/tools/dencoder/ the string should enocde to: Pe%C3%B4n
根据: http ://meyerweb.com/eric/tools/dencoder/该字符串应包含:
Pe%C3%B4n
When I use urlencode($name)
I get Pe%F4n
当我使用
urlencode($name)
我得到Pe%F4n
SOOOO Lost on this. 太丢人了。
I am trying to use the encoded string in the following manner: 我试图以以下方式使用编码的字符串:
Fails: 失败:
http://us.battle.net/api/wow/character/Kil%27jaeden/Pe%F4n?fields=statistics
http://us.battle.net/api/wow/character/Kil%27jaeden/Pe%F4n?fields=statistics
Works: 作品:
http://us.battle.net/api/wow/character/Kil%27jaeden/Pe%C3%B4n?fields=statistics
http://us.battle.net/api/wow/character/Kil%27jaeden/Pe%C3%B4n?fields=statistics
mycode: mycode:
$name = mysqli_real_escape_string($connection, $_POST['name']);
$name = urlencode($name);
EDIT: 编辑:
$name = $_POST['name'];
$realm = mysqli_real_escape_string($connection, $_POST['realm']);
$locale = mysqli_real_escape_string($connection, $_POST['locale']);
$toon = query_blizz_toon($name, $realm, $locale);
function query_blizz_toon($name, $realm, $locale){
$realm = urlencode(stripslashes($realm));
$name = urlencode($name);
$q = 'http://'.$locale.'.battle.net/api/wow/character/'.$realm.'/'.$name.'?fields=statistics';
echo $q;
$character = @file_get_contents($q);
$character = json_decode($character);
return $character;
}
echo $q
ouputs: http://us.battle.net/api/wow/character/Kil%27jaeden/Pe%F4n?fields=statistics
echo $q
输出: http://us.battle.net/api/wow/character/Kil%27jaeden/Pe%F4n?fields=statistics
://us.battle.net/api/wow/character/Kil%27jaeden/Pe%F4n?fields= http://us.battle.net/api/wow/character/Kil%27jaeden/Pe%F4n?fields=statistics
Still getting the wrong encoding even without the escaping... :/ 即使没有转义也仍然得到错误的编码...:/
EDIT: 编辑:
According to this site: http://www.degraeve.com/reference/urlencoding.php 根据此网站: http : //www.degraeve.com/reference/urlencoding.php
%F4
is the correct encoding for ô
... %F4
是ô
的正确编码。
Well i am getting exactly what you are expected to get. 好吧,我正得到您所期望得到的。 Your
mysqli_real_escape
is the culprit here. 您的
mysqli_real_escape
是这里的罪魁祸首。 Remove it. 去掉它。
Also, make use of Prepared Statements
, so that you don't have to focus on escaping and stuff. 另外,利用
Prepared Statements
,这样您就不必专注于转义和填充。
<?php
$name = 'Peôn';
echo $name = urlencode($name);
OUTPUT: 输出:
Pe%C3%B4n
$name = rawurlencode(utf8_encode($name));
Does the trick. 绝招。 Wish i knew why...
希望我知道为什么...
The problem is with the page that has the form. 问题在于具有表单的页面。
The web browser is sending the user input encoded in latin-1, but you want it to send UTF-8. Web浏览器正在发送以latin-1编码的用户输入,但是您希望它发送UTF-8。 One way to fix that is sending the Content-Type header to tell the browser that the page is in UTF-8, if you can't do that you can use the HTML meta tag to do the same, yet another is declaring the
accept-charset
in the form tag. 解决该问题的一种方法是发送Content-Type标头,以告知浏览器该页面位于UTF-8中,如果不能执行此操作,则可以使用HTML meta标签执行相同操作,另一种方法是声明
accept-charset
在表单标记中。
<form accept-charset="UTF-8" method="POST" action="...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.