I posted this on another forum too, but thought I would ask here as well. I'm working on an RSS reader and I'm running into a little snag, so I thought I'd ask to see what people thought the best approach might be. I want to convert it to JSON before I turn it over to the JavaScript, so I'm using the simplexml and JSON functions. It's working okay except that it also converts any embedded HTML into JSON as well, which makes it hard for the JavaScript class I wrote for it. What I'm thinking about doing is entity-encoding everything inside the (RSS) description tag, but I'm not quite sure the best way to do that or if that's the best solution because I might run into some problems if the feed is about HTML or JavaScript. Any suggestions?
Here's my code so far:
PHP Code:
$url = urldecode($_POST['url']); $rawFeed = file_get_contents($url); $rawFeed = preg_replace('#<!\[CDATA\[(.*)\]\]>#', '', $rawFeed); $feed = simplexml_load_string($rawFeed); echo json_encode($feed);
On a side note, should I be stripping script tags as well? Also, if you have any further suggestions for this, I'd also like to hear them. Thanks.
|