Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with SimpleXML and htmlentities

Status
Not open for further replies.

hansu

Programmer
Mar 12, 2002
89
Hi
I load an xml file with simplexml_load_file into the variable $xml. The element 'data' of the xml-file contains an attribute 'temp' with a temperature in degrees Celcius:
<data temp="18°C" fineweather="70%" frostborder="3800"/>

To transform it to xhtml I use:
$vormTemp = htmlentities($xml->weatherdata->day->data[@temp]);

That produces:
18&Acirc;&deg;C which of course looks like 18°C.

I have no idea why the &Acirc; is generated.

Thanks for your assistance.
 
Would it be possible to post a bigger portion of your source XML file?

Do you have control over the content of that XML file?

I've tried passing '18°C' into the htmlentities function and that produces the expected 18&deg;C.

Just a shot in the dark, but you could try specifying a different charset as a parameter to htmlentities.

Clive
Runner_1Revised.gif

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer." (Paul Ehrlich)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Hi Stretchwickster

Thanks for your hint.
I modified
Code:
$vormTemp = htmlentities($xml->weatherdata->day->data[@temp]);
into
Code:
$vormTemp = htmlentities($xml->weatherdata->day->data[@temp],HTML_ENTITIES,'UTF-8');
and it works fine now.

Thanks again
Hans Ulrich
 
You're welcome.

Clive
Runner_1Revised.gif

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer." (Paul Ehrlich)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top