I have a string with unicode characters that I am transferring via HTTP. This string was encoded with Javascript's encodeURIcomponent()
. Is there an equivalent function in php to Javascript's decodeURIComponent()
?
What is the equivalent of JavaScript's decodeURIcomponent in PHP?
Asked Answered
urldecode()
However you do not need to use it on $_REQUEST variables, which are already decoded automatically.
i have used $_POST for fetching,but urldecode() doesnt work on unicode characters. –
Callous
<?php 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');; } ?> –
Reprehend
@ExplosionPills was that double semicolon at the end a typo? –
Cheyney
Side note: I am using
encodeURIComponent()
to pass data to a Laravel application and the request doesn't seem to automagically decode the value. –
Ingra Be careful:
urldecode('+') === ' '
and decodeURIComponent('+') === '+'
. Currently dont know why. –
Tracitracie rawurldecode()
which does not decode plus to space charactor
© 2022 - 2024 — McMap. All rights reserved.