Link to home
Start Free TrialLog in
Avatar of AlexanderR
AlexanderRFlag for Canada

asked on

html_entity_decode returns different results in linux from windows

When i am in windows html_entity_decode seems to work fine.  It propperly replaces   with a space. When i apply the same code in linux, it returns a weird white question mark within a black square (rombus).
It seems to do other characters propperly, like &lt; to <, but why it cant do &nbsp; ?.  Of course i can do str_replace("&nbsp;", " ", $mystring), but that dont look right.

Can someone please explain?

PHP 5.2.1 Kubuntu.
Avatar of dryliketoast
dryliketoast

character set is probably not defined in your html header. when character codes don't match up, you get weird characters.

my guess is php is printing in, lets say, UTF8 and your HTML header states (or may not even be included) to display characters using ISO 8859-1 Latin 1, for example

try this line in your HTML, it may fix the problem

<meta http-equiv="content-type" content="text/html; charset=UTF-8">
Avatar of AlexanderR

ASKER

Thanks, but it didnt.

Its not just a problem of browser output. (that would be easy, just change the display coding, like you said).  However problem goes way deeper.
I have other functions down the line, that split the resulting string into multiple strings based on a space, then each of those are used as either SELECT or INSERT (depends on what stage of the application you are at) for appropriate columns in the DB.  Of course all of that fails because of that one character, so explode(" ", $afterhtmldecode) doesnt work.
You could as why dont i do explode("&nbsp;"$string), but what if at some point the space is an actual space rather than &nbsp.
Does it work if you specify a locale:

setlocale(LC_ALL, 'en_GB.UTF-8');

Just a long shot. I'm having trouble getting PHP to work with that locale myself.
(Ah, you can check which locales are installed in Ubuntu by typing "locales -a" in the terminal.)
(Sorry, there's no s, it's just "locale -a".)
setlocale didnt work. I even tried some other locales like en_US, but all same.
ASKER CERTIFIED SOLUTION
Avatar of dryliketoast
dryliketoast

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks.  I hope B is satisfactory grade, as i did not get a true solution or explanation, but only a workaround.