Created
November 27, 2015 22:26
-
-
Save rhettl/c31fb2e48f80d80b83c9 to your computer and use it in GitHub Desktop.
Example of xml parsing of RSS with simpleXML and CDATA workaround
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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