Results 1 to 4 of 4

Thread: [RESOLVED] How to decode " %u5D16 " in PHP?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2008
    Posts
    268

    Resolved [RESOLVED] How to decode " %u5D16 " in PHP?

    Hi, how would I go about decoding text like this in PHP:

    %u85E4%u5CA1%u85E4%u5DFB%u3068%u5927%u6A4B%u306E%u305E%u307F - %u5D16%u306E%u4E0A%u306E%u30DD%u30CB%u30E7

    It appears it is URL encoded, but the php URLDecode function does not properly decode the text to its intended format:

    藤岡藤巻と大橋のぞみ - 崖の上の ....

    Thanks in advance!

    David

  2. #2
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    1,023

    Re: How to decode " %u5D16 " in PHP?

    Conforming HTML user agents may receive or output a document, or represent a document internally, using any character encoding. A character encoding represents some subset of the document character set. Character encodings such as ISO-8859-1 (commonly referred to as "Latin-1" since it encodes most Western European languages), ISO-8859-5 (which supports Cyrillic), SHIFT_JIS (a Japanese encoding), and euc-jp (another Japanese encoding) save bandwidth by representing only slices of the document character set.
    http://www.w3.org/TR/WD-html40-970708/charset.html


    its all about the charset


    or why not just copy it right in?



    or did i misunderstand this? btw this doesn't look like a url: Fujioka Fujimaki & Nozomi Ohashi - on the cliff

  3. #3
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: How to decode " %u5D16 " in PHP?

    The issue is that those are UTF-8 encoded so you'll need to decode those first. I hit this a while back and wrote a script to get around it.

    Code:
    function urldecode_utf8($input)
    {
      $input =  urldecode($input);
      $result = preg_replace('/%u([0-9a-f]{3,4})/i', '&#x\\1;', $input);
      return html_entity_decode($result, null, 'UTF-8');
    }
    That should do what you need.

    Edit:

    One note: ensure that you set the content type header to output UTF-8 contant or it'll render incorrectly.
    My Blog.

    Ryan Jones.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2008
    Posts
    268

    Re: How to decode " %u5D16 " in PHP?

    Great! Thanks, worked a charm.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width