Search code examples
phpcharacter-encodingurlencode

Why is my PHP variable displayed as incomprehensible with a character sequence of % instead of its real value in Chinese?


I'm trying to use this embed PHP Package (https://github.com/oscarotero/Embed/). However, I when I try to display the display of the Title with the variable $info->title of all the Pages having the Asian languages like that of the URL https://zh.wikipedia.org/wiki/亞馬遜公司, this returns me %E4%BA%9E%E9%A6%AC%E9%81%9C%E5%85%AC%E5%8F%B8 as title instead of this as the real title 亞馬遜公司.

Why the display of an incomprehensible character like: %E4%BA%9E%E9%A6%AC%E9%81%9C%E5%85%AC%E5%8F%B8 instead of 亞馬遜公司? ??

So how do I get my $info->title variable to display as it should: 亞馬遜公司 ???

Thank you please help me.


Solution

  • You can decode the string. Maybe the library does not.

    $title = '%E4%BA%9E%E9%A6%AC%E9%81%9C%E5%85%AC%E5%8F%B8';
    var_dump(rawurldecode($title));
    

    will print

    string(15) "亞馬遜公司"