How to get valid XML titles from feeds using SimplePie?

chipkhan

New Member
One ongoing problem I have with PHP and SimplePie is feeds/web services that are encoded poorly, include, garbage characters or what have you.I have found it necessary when calling get_title() on feeds or items to then check and parse the returned string, trying to escape or replace characters in order become valid XML as I'm trying to create an RSS feed by merging other RSS feeds.I documented my technique which is based on previous SimplePie examples. It works until some blogger puts some strange character in their blog or post title.Merging feeds with PHP and SimplePieHowever when I upgraded to the latest version of PHP I was once again confronted with this issue. I've tried finding a Regex or string replace that I can use, but it seems there is always another feed or post that will break my code.This is what I currently am using: print('' . $feed->get_title() . ' : ' . preg_replace("/&#?[a-z0-9]{2,8};/i", "", $item->get_title()) . '' . "\n");It appears my simple example will need some more try and catch exception handling code added to it, it would be nice if SimplePie had a get_safeTitle() or something similar that escapes or properly encodes everything so client code doesn't have to come up with a solution every time they encounter unexpected garbage in a post title.
 
Back
Top