Forum Moderators: open

Message Too Old, No Replies

JS escaped string to php

escape php js javascript

         

Seregwethrin

10:21 pm on Apr 22, 2007 (gmt 0)

10+ Year Member



Hello all;

%u015Fa% this is the escaped character of this [img142.imageshack.us]

How can i unescape it in php? I've tried urldecode, rawurldecode but they are not working. How can i do?

Dabrowski

11:38 pm on Apr 22, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, if you check out:
[unicode.org...]

You'll see that 015F is the Unicode character for an S with a squiggly thing on, which I guess is right, so PHP must be adding %u as a unicode identifier, but I have no idea what the a% is at the end, a terminator maybe?

I've actually studied Unicode and wrote a binary encoder/decoder, but it's at the office.

A quick Google found this though, apparently HTML supports Unicode encoded characters as:

ş

But you need to tell the browser you're going to be using these characters, by putting this in your <head>:

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

So, your JS simply needs to convert the PHP version of Unicode to the browsers'. Now there are 2 ways to do this, one for pre-processing (you're using JS to add content onto the page), one for post-processing (the character is already there).

As you're using PHP I can assume the character is already on the page, so we can simply use a RegExp to convert any number of these that are already in the HTML source.

Here's my test page, you can see the 1 line JS source code in there. Try it for yourself.

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Test Page</title>
<script>

function php_unescape() {
document.body.innerHTML = document.body.innerHTML.replace( /(%u([0-9A-F]{4})a%)/gi, "&#x$2;");
}

</script>
</head>

<body onLoad='php_unescape();'>

I wonder what these characters are going to be?<br>

%u015Aa% %u015Ba% %u015Ca% %u015Da% %u015Ea% %u015Fa% %u0160a% %u0161a%

</body>

</html>