Forum Moderators: coopster

Message Too Old, No Replies

decoding javascript escape in php

         

tinyblob

4:50 pm on Jan 29, 2004 (gmt 0)

10+ Year Member



Hi there,
I've used the javascript "escape()" function to prepare some data to be saved in a cookie. I'm now trying to read the data in PHP but not having much luck.. Is there a way i can unescape this in php?

Thanks :)

tinyblob

4:56 pm on Jan 29, 2004 (gmt 0)

10+ Year Member



to refine the problem a little more..
we're trying to pass a "+" sign in the cookie (set by javascript) to a php page. currently php is reading the cookie (it's not escaped) but interpretting the + as a space, we thought the solution would be to use the escape function, but i'm not sure that will help..
any advice?

jatar_k

9:10 pm on Jan 29, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



maybe try to serialize [ca.php.net] and unserialize [ca.php.net] the data

isitreal

11:03 pm on Jan 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If the thing you are trying to pass is a '+' sign, that's not escaped in javascript escape(), as you can see if you run this sample:
<script type="text/javascript">
test=escape('this is+webmaster world');
document.write(test);
</script>
what is output is this:
this%20is+webmaster%20world

The problem I think is that php is treating the '+' as a space, what you would get if in php you used the urlencode(string) function, in which spaces are changed into +.

in php:
<?php
$test=urlencode('this is+webmasterworld');
echo $test;
?>

puts out:
this+is%2Bwebmasterworld

so maybe you might try putting in %2B instead of + in the javascript side, then use urldecode() in php to get back to the +, if that's what you are trying to do, it's not completely clear to me though.