UTF-16 has two variations: big-endian and little-endian. They differ in the order of the bytes in the code units: the character U+1234 would be encoded as '\x12\x34'
in big-endian, but as '\x34\x12'
in little endian.
It looks like iconv is assuming different versions on different systems. You make it use the big-endian version on all systems by using utf-16be
:
return preg_replace("/\\\u([0-9A-F]{4})/ie", "iconv('utf-16be', 'utf-8',hex2str(\"$1\"))", $str);