You can directly convert objects from their escaped numeric values. For many years I had the following function. I did not write this, and I am afraid that I do not remember where I found it. It's a little hack, but damn useful, I think.
<?php function code2utf($num) { if($num<128)return chr($num); if($num<2048)return chr(($num>>6)+192).chr(($num&63)+128); if($num<65536)return chr(($num>>12)+224).chr((($num>>6)&63)+128).chr(($num&63)+128); if($num<2097152)return chr(($num>>18)+240).chr((($num>>12)&63)+128).chr((($num>>6)&63)+128).chr(($num&63)+128); return ''; } print "a" . code2utf(0x3000) . "b" . code2utf(0x1f44d) . "\n";
And when I run this, I see:
$ php -f utftest a bπ
Note that what looks like two spaces is one double-wide character.
Perhaps you can use the above function to create your input string, for example:
str_replace(code2utf(0x3000),"",$mystring);
The obvious advantage of such a solution as the WebChemist copy and paste solution is that it is fully programmatic and does not require any special functions as part of the programmer's tools. You will not accidentally overwrite the ID_SPACE character when reformatting your code, and the function can be reused for other UTF8 characters that you may need, without having to have these characters inside your code.
Of course, otherwise you can do it with the PHP built-in html_entity_decode() function. The following are results identical to my function using HTML escaped characters as input:
$ php -r 'print html_entity_decode("a b👍") . "\n";' a bπ
source share