Help - Search - Members - Calendar
Full Version: XML php functions
Pixel2Life Forum > Help Section > PHP, ASP, MySQL, JavaScript and other Web/Database Programming Help
Lang
I am having some issues with special characters while reading in an XML file, using PHP's XML libraries.

For instance, characters like &, or ' get cut off.

<TagName>This & That</TagName>

The data returned will be " That". Any data before the character gets cut off.

At first I tried replacing & says with their HTML entity. That didn't do much good as every HTML entity has an ampersand.

Has anyone ever had this issue before? How did you get around it?

Thanks,
Lang
rc69
That's weird, i've never experienced that issue. Personally, i would expect the stuff after the '&' to get cut off instead of the stuff before it.

However, have you tried manually replacing the '&' with '&amp;' and testing with that (i.e. make the edit it notepad, then run the script to see if it works as opposed to using str_replace())?
Lang
Thanks for the reply rc,

I did what you suggested, but had the same result. Just a tidbit, when there's a special character in an attribute to a tag it parses fine.

For example:

<Tag attribute="It's a special character">
<TagTwo>Special ' character</TagTwo>
</Tag>

The data in attribute is easy to get. I turn it into &# 39; (html entity for apostrophe) but in TagTwo it gets cut off. Could the # sign be affecting it?

This is my header:
CODE
<?xml version="1.0" encoding="UTF-8" ?>
Neil
Can you please show us the code you're using to read the xml and a link to the xml feed you're trying to read from?
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.