urldecode like decodeURIComponent

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pedroz
Forum Commoner
Posts: 99
Joined: Thu Nov 03, 2005 6:21 am

urldecode like decodeURIComponent

Post 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 “ ?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: urldecode like decodeURIComponent

Post 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
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply