0

Is ther any built in function in PHP to decode

przysi%25C4%2599gam%2520s%25C5%2582u%25C5%25BCy%25C4%2587

into

przysięgam służyć

?

1
  • 1
    Are you sure, that the program generating these strings knows what it's doing? If it is an UTF-8 url encoded string, it should read przysi%25%C4%25%99gam..., that is, with both bytes url-encoded. Commented Apr 1, 2010 at 11:10

4 Answers 4

2

Ok, Gordon and Manos, you're both right (and both wrong ;)

It's just normal 'urldecode', but applied twice

$a = "przysi%25C4%2599gam%2520s%25C5%2582u%25C5%25BCy%25C4%2587";
$b = urldecode(urldecode($a));
var_dump($b);
Sign up to request clarification or add additional context in comments.

1 Comment

This is interesting, because the String is being posted a mortal JS script using encodeURLEntity() -- no idea why the stuff is encoded twice then
2

My guess is that you have issues with urldecode and multibyte characters. Urldecode can only decode 8 bit characters and your string contains multibyte characters.

Check the urldecode manual page comments for some solutions.

Comments

2

urldecode — Decodes URL-encoded string

But I think that won't work on multibyte strings. See the comments on the manual page for possible userland workarounds and also http://www.zend.com//code/codex.php?ozid=839&single=1

1 Comment

Negative. Urldecode fails on that one badly, as it decodes only %## characters.
0

Have you tried this:

    function utf8_urldecode($str) {
      $str = preg_replace("/%u([0-9a-f]{3,4})/i","&#x\\1;",urldecode($str));
      return html_entity_decode($str,null,'UTF-8');;
  }

Taken from http://php.net/manual/en/function.urldecode.php

Edit: Your initial string is messed up. Did you urlencode it twice? Cause utf8_urldecode(utf8_urldecode($encoded string)) gives the correct result.

1 Comment

gave przysi%C4%99gam%20s%C5%82u%C5%BCy%C4%87 on my machine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.