Skip to content

Instantly share code, notes, and snippets.

@rhettl
Created November 27, 2015 22:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rhettl/c31fb2e48f80d80b83c9 to your computer and use it in GitHub Desktop.
Save rhettl/c31fb2e48f80d80b83c9 to your computer and use it in GitHub Desktop.
Example of xml parsing of RSS with simpleXML and CDATA workaround
<?php
/**
* Created by PhpStorm.
* User: rhett
* Date: 11/27/15
* Time: 1:43 PM
*/
/**
* Parse description to return scripted version for txtToSpeech engine
*
* @param String $desc description with html from rss feed
*
* @return String string for text to speech engine.
*/
function parseDesc($desc) {
// do something here
return $desc;
}
$ch = curl_init("https://community.elitedangerous.com/galnet-rss");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$xml = curl_exec($ch);
curl_close($ch);
$xml = simplexml_load_string($xml);
foreach($xml->channel->item as $item) {
$pub = array(
'guid' => (string) $item->guid,
'title' => (string) $item->title,
'description_original' => (string) $item->description,
'pubDate' => (string) $item->pubdate
);
$pub['description'] = parseDesc($pub['description_original']);
var_dump($pub);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment