• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 449
  • Last Modified:

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.
0
AlexanderR
Asked:
AlexanderR
  • 3
  • 3
  • 2
1 Solution
 
dryliketoastCommented:
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">
0
 
AlexanderRAuthor Commented:
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.
0
 
HackneyCabCommented:
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.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
HackneyCabCommented:
(Ah, you can check which locales are installed in Ubuntu by typing "locales -a" in the terminal.)
0
 
HackneyCabCommented:
(Sorry, there's no s, it's just "locale -a".)
0
 
AlexanderRAuthor Commented:
setlocale didnt work. I even tried some other locales like en_US, but all same.
0
 
dryliketoastCommented:
> 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.

$chunks = preg_split('/&nbsp;| /', $afterhtmldecode)

would probably solve that issue

otherwise, i'd say its a linux issue, perhaps a config file is using the wrong setting - its out of my depth tho to be honest. i have only been using linux for 8 months or so

hope that helps anyway
0
 
AlexanderRAuthor Commented:
Thanks.  I hope B is satisfactory grade, as i did not get a true solution or explanation, but only a workaround.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now