urlencode,PHP中的符号错误

时间:2011-11-23 03:17:24

标签: php html

我目前正在为从doc文件生成的html文件编写解析器。字符串包含像alpha beta等符号......问题是当我执行urldecode(urlencode(alpha));时它没有给出符号..它返回其他内容。

要查找我的问题,请检查

urldecode("%0A%20%20If%20%3Ci%20style%3D%22mso-bidi-font-style%3Anormal%22%3E%CE%B1%3C%2Fi%3E%2C%20b%2C%20g%0A%20%20be%20the%20zeroes%20of%20the%20polynomial%20%3Ci%20style%3D%22mso-bidi-font-style%3Anormal%22%3Eax%3C%2Fi%3E%3Csup%3E3%3C%2Fsup%3E%0A%20%20%2B%20b%3Ci%20style%3D%22mso-bidi-font-style%3Anormal%22%3Ex%3C%2Fi%3E%3Csup%3E2%3C%2Fsup%3E%20%2B%20c%3Ci%20style%3D%22mso-bidi-font-style%3Anormal%22%3Ex%3C%2Fi%3E%20%2B%20d%2C%20the%20the%20value%20of%20%3Ci%20style%3D%22mso-bidi-font-style%3Anormal%22%3E%26nbsp%3B%CE%B1%3C%2Fi%3Eb%20%2B%20bg%20%2B%20g%3Ci%20style%3D%22mso-bidi-font-style%3Anormal%22%3E%20%CE%B1%3C%2Fi%3E%26nbsp%3B%20is%0A%20%20");

有没有办法解决这个问题?

2 个答案:

答案 0 :(得分:1)

您的字符集不匹配。该符号可能被解码为UTF-8,但您将该网站解释为其他内容,可能是Latin-1。要确认这一点,请从浏览器的View>中选择UTF-8。编码菜单。设置适当的header,以便始终使用UTF-8解释网站:

header('Content-Type: text/html; charset=utf-8');

这意味着您还需要确保网站的其余部分是有效的UTF-8,或者与文字的编码匹配。

答案 1 :(得分:-1)

You can used javascript function  unescape($urlfordecode);
Its decode your url, if you want to mannually check then used following url

http://meyerweb.com/eric/tools/dencoder/

使用以下代码进行php

  $urlfordecode ="Your encoded url place here";

    $a = explode('&', $urlfordecode);
    $i = 0;
    while ($i < count($a)) {
        $b = explode('=', $a[$i]);
        echo 'Your decoded url is  =>  </br>',htmlspecialchars(urldecode($b[0])), 
        htmlspecialchars(@urldecode($b[1])), "<br />\n";
        $i++;
    }