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条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度