clops
clops

Reputation: 5235

POST String Decoding in PHP

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ć

?

Upvotes: 0

Views: 3249

Answers (4)

user187291
user187291

Reputation: 53940

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

Upvotes: 2

Manos Dilaverakis
Manos Dilaverakis

Reputation: 5869

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.

Upvotes: 0

Gordon
Gordon

Reputation: 316969

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

Upvotes: 2

ChrisR
ChrisR

Reputation: 14447

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.

Upvotes: 2

Related Questions