xml_parse() and php and ampersands

If you're ever parsing XML with PHP and your data has an ampersand between two tags you might notice this: PHP will repeatedly call the character data handler on each piece of that data after splitting it at the ampersand.

For example, if you have the value X&Y between a start tag and end tag the PHP xml_parser will call the cdata handler 3 times where it should have called it just once.

If your tag is called title, fix it like this:

case "TITLE": $TITLE .= $cdata; break;

This way, it'll append the X to the & to the Y and give you the correct result of X&Y instead of just Y. Additionally, for data not containing an ampersand, it'll just get called once and also set it correctly.