With htmlentities():
<?php
echo htmlentities("\xE4");
?>
However, it's worth noting that:
- Sessions do not care about character encoding.
- HTML entities are not required in HTML Unicode documents (except for chars with a special meaning in HTML such as
<
and >
).
So this won't fix your problem, it will just hide it ;-)
Update
I had overlooked the reference to \00e4
in the original question. The ä character corresponds to the U+00E4
Unicode code point. However, PHP does not support Unicode code points. If you need to type it in your PHP code and your keyboard does not have such symbol, you can save the document as UTF-8 and then provide the UTF-8 bytes (c3 a4) with the double quote syntax:
<?php
// \[0-7]{1,3} or \x[0-9A-Fa-f]{1,2}
echo "\xc3\xa4";
?>
Still, this has no relation to sessions or HTML. I can't understand what your exact problem is.
Second update
So serialize() cannot handle associative arrays and json_decode() cannot be fed with json_encode()'s output...
<?php
$associative_array = array(
'foo' => 'ä',
'bar' => 33,
'gee' => array(10, 20, 30),
);
var_dump($associative_array);
echo PHP_EOL;
var_dump(serialize($associative_array));
echo PHP_EOL;
var_dump(unserialize(serialize($associative_array)));
echo PHP_EOL;
var_dump(json_encode($associative_array));
echo PHP_EOL;
var_dump(json_decode(json_encode($associative_array)));
echo PHP_EOL;
?>
...
array(3) {
["foo"]=>
string(2) "ä"
["bar"]=>
int(33)
["gee"]=>
array(3) {
[0]=>
int(10)
[1]=>
int(20)
[2]=>
int(30)
}
}
string(83) "a:3:{s:3:"foo";s:2:"ä";s:3:"bar";i:33;s:3:"gee";a:3:{i:0;i:10;i:1;i:20;i:2;i:30;}}"
array(3) {
["foo"]=>
string(2) "ä"
["bar"]=>
int(33)
["gee"]=>
array(3) {
[0]=>
int(10)
[1]=>
int(20)
[2]=>
int(30)
}
}
string(42) "{"foo":"\u00e4","bar":33,"gee":[10,20,30]}"
object(stdClass)#1 (3) {
["foo"]=>
string(2) "ä"
["bar"]=>
int(33)
["gee"]=>
array(3) {
[0]=>
int(10)
[1]=>
int(20)
[2]=>
int(30)
}
}
It appears to me that you are adding several layers of complexity to a simple script because you are making assumptions about how some PHP functions work instead of checking the manual or testing yourself. At this point, the information provided hardly resembles the original question and we still haven't seen a single line of code.
My advice so far is that you try to stop debugging your app as a whole, divide it into smaller pieces and use var_dump() to find out what each of these parts actually generate. Don't assume things: test stuff yourself. Also, take into account that PHP doesn't Unicode natively as others languages do. Every single task that involves double-byte string handling must be carefully implemented with the appropriate multi-byte functions, which often require to hard-code the character encoding.