dongtieshang5429 2013-09-09 07:30
浏览 174
已采纳

从编码的URL显示日语字符

I was doing a small task on php (Even tried the same task on cold-fusion).

There is an API that sends me URL of following Pattern as a data:

  1. http://127.0.0.1:8080/test/index.php?brand=%93%FA%8EY%8E%A9%93%AE%8E%D4

  2. http://127.0.0.1:8080/test/index.php?brand=Airtel%20India%20Mobile%20Corporation

I have to display the brand name, which is crucial part of the task. When I simply prints brand name as:

echo $_GET['brand']

, than I am getting correct output for URL 2.

URL 2 prints Airtel India Mobile Corporation.

However, I am getting wrong output for 1. URL 1 prints weird set of characters. Please Note URL-1 brand contains name of a Japanese company(Nissan Motor Co., Ltd.) in Japanese.

URL 1 : echo prints

“úŽYŽ©“®ŽÔ

I realized its an encoding problem. Then What I did is:

Right-Clicked on IE->Selected Encoding-> Selected Japanese(Shift_JIS) as Encoding.

As soon as I selected Japanese(Shift_JIS), I got the correct output.

日産自動車

How can I do it using PHP (and/or) Cold-Fusion? In other words, how can I display correct/desired o/p by PHP( or coldfusion) code (script).

Any help is appreciated.

  • 写回答

2条回答 默认 最新

  • doumi9618 2013-09-09 07:56
    关注

    I think you can use this function.

    http://jp2.php.net/manual/ja/function.mb-convert-encoding.php

    $str = $_GET["brand"]; //%93%FA%8EY%8E%A9%93%AE%8E%D4
    $str = mb_convert_encoding($str, "SJIS", "auto");
    echo $str; //日産自動車
    

    EDITED

    $str = $_GET["brand"]; //%93%FA%8EY%8E%A9%93%AE%8E%D4
    $str = urldecode($str);
    echo $str; //日産自動車
    

    This should work.

    There is "urlencode" function that do the opposite thing of "urldecode" function as well.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向