How to Decode Javascript Escaped Text with PHP

By | June 21, 2008

Recently I had to decode a string that was encoded with javascript, using ascii codes of symbols. In JavaScript everything looks simple – unescape() allows to get a readable string. But I had to do it with PHP and the first thought was to use chr and ord functions. But there was a simple solution as usual.

I had to use urldecode to obtain readable text from JavaScript escaped string. Though my string was not an URL, everything went well. So this function might be useful not only for URL decoding, but also helps to deal with Javascript encoding.