Page 1 of 1

urldecode like decodeURIComponent

Posted: Thu Sep 01, 2011 7:33 pm
by pedroz
1. With the function decodeURIComponent in JavaScript

Decoding this
%E2%80%9C
will get the following

Code: Select all

<script type="text/javascript">
function decode() {
	var obj = document.getElementById('dencoder');
	var encoded = obj.value;
	obj.value = decodeURIComponent(encoded.replace(/\+/g,  " "));
}
</script>

<textarea cols="80" rows="20" id="dencoder"></textarea>
<div>
<input type="button" onclick="decode()" value="Decode">
</div>
Working!


2. PHP not working
However, I am not able to decode it in PHP.
Already tried...

Code: Select all

echo ord(utf8_decode(urldecode("%E2%80%9D"))); 
echo "<br>";
echo ord(urldecode("%E2%80%9D")); 
echo "<br>";
// not getting this value
echo ord('“');

Any idea to decode %E2%80%9D in php and get this char “ ?

Re: urldecode like decodeURIComponent

Posted: Thu Sep 01, 2011 9:40 pm
by s.dot
The PHP comments may be able to help you
Like this one http://us3.php.net/manual/en/function.u ... .php#92777
It appears you want to get an html entities from a utf8 representation of the character