Why the result from PHP chr(238) is different with javascript String.fromCharCode(238) and how to fix that?

So the old program was in PHP and I would like to rewrite in node.js (javascript).

Why the result from PHP chr(238) is different with javascript String.fromCharCode(238) and how to fix that?

PHP: chr(238) =

Javascript: String.fromCharCode(238) = î

The result from above is used as header for TCP connection.

Upvotes: 1

Views: 303

Answers (1)

Use mbstring here lib to process unicode in PHP. Something like this:

mb_chr(238);

Or in PHP 5:

<?php
function exchr($u) {
    return mb_convert_encoding('&#' . intval($u) . ';', 'UTF-8', 'HTML-ENTITIES');
}
echo exchr(238);

Upvotes: 2

Related Questions