<title>’ . $CIDArray[0] . ’ (’ . $CIDArray[1] . ') called on ’ . $props[‘origdate’] . '</title>
So, what’s happening is that in a caller ID string like “Mike & Mary” the RSS feed is giving me an XML parsing error because the & is not a valid character. I think the ereg line above will allow me to substitute the ampersand character, but how exactly would I modify the line so that it replaces it with the word “and” so that instead of “Mike & Mary” it says “Mike and Mary”.
I can’t answer this in PHP-specific terms since I’m not a PHP programmer and browsing the API doesn’t make it obvious, but I can explain something you probably want to consider before deciding on your “replace & with ‘and’” solution: the problem is not that your string has an & sign in it, the problem is that your string is not XML encoded. If you want to write any old string into an RSS feed, all you have to do is XML encode it. It should be as simple as:
function makeTitleElement($anyOldString)
{
return '<title>' . xmlEncodeMyString(anyOldString) . '</title>';
}
then you write out:
makeTitleElement($CIDArray[0] . ' (' . $CIDArray[1] . ') called on ' . $props['origdate']);
“xmlEncodeMyString” is a mythical function that takes input like “Mike & Mary” and returns the same string encoded so it’s safe to write into XML (“Mike & Mary” in this case). You need to find out what PHP library function does that sort of thing. (and sorry, but this is approximately where my PHP knowledge ends)
The reason you want to do this with a standard function instead of your own ad-hoc search and replace is that there may be other cases you won’t remember to fix up until you run into a problem (apostrophes? greater-than signs?). The point of the library routines is that someone else has already worried about this problem for you.
htmlspecialchars? That is just bizarre. At first, I was going to object because a routine that does HTML encoding is very different from a routine that does XML encoding (see the huge difference in the list of entities for each here), but it turns out that “htmlspecialchars” would be better named “xmlspecialchars”. However, it appears to have a bug if it’s going to be used for XML encoding: it doesn’t appear to handle quotes (particularly single quotes, which are often used as apostrophes) correctly. Also, the optional “double_encode” parameter makes me think this is an API designed by someone who doesn’t know what they’re doing.