tags:

views:

364

answers:

4

I am building a XML RSS for my page. And running into this error:

error on line 39 at column 46: xmlParseEntityRef: no name

Apparently this is because I cant have & in XML... Which I do in my last field row...

What is the best way to clean all my $row['field']'s in PHP so that &'s turn into &

+2  A: 

It's called htmlentities() and html_entity_decode()

Ólafur Waage
XML does not share all of the same *named* entities as HTML - having only 5 predefined entities (amp, lt, gt, quot, and apos). Unless the XML document has a DTD attached to it that includes all of the HTML named entities, using htmlentities(), which converts could convert some characters into entities that an XML parser is not required to support.
Jason Musgrove
So what is best to use then?
ian
@ian: Given Gumbo's description of `htmlspecialcharacters()`, I would go with that (as it only touches the 5 characters with predefined entities in XML)
Jason Musgrove
+3  A: 

Use htmlspecialchars to encode just the HTML special characters &, <, >, " and optionally ' (see second parameter $quote_style).

Gumbo
A: 
Frederico
Not sure why I would want to revert... This is for a RSS feed.
ian
+2  A: 

Really should look in the dom xml functions in php. Its a bit of work to figure out, but you avoid problems like this.

Aduljr
How so? Point me to something and I will figure it out.
ian