Jump to content


Photo

XML php functions


  • This topic is locked This topic is locked
3 replies to this topic

#1 Lang

Lang

    Young Padawan

  • Members
  • Pip
  • 198 posts
  • Gender:Male
  • Location:Ontario, Canada

Posted 29 September 2009 - 11:43 AM

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

Edited by Lang, 29 September 2009 - 11:44 AM.


#2 rc69

rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 30 September 2009 - 09:34 AM

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())?

Edited by rc69, 30 September 2009 - 09:35 AM.


#3 Lang

Lang

    Young Padawan

  • Members
  • Pip
  • 198 posts
  • Gender:Male
  • Location:Ontario, Canada

Posted 30 September 2009 - 07:31 PM

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:
<?xml version="1.0" encoding="UTF-8" ?>

Edited by Lang, 30 September 2009 - 07:32 PM.


#4 Neil

Neil

    Past Staff Member

  • Members
  • Pip
  • 149 posts
  • Gender:Male
  • Location:Australia

Posted 01 October 2009 - 12:22 AM

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?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users