note 74456 deleted from ref.xml by danbrown
| From: | danbrown@php.net | Date: | Wed, 03 Mar 2010 18:54:45 +0000 |
| Subject: | note 74456 deleted from ref.xml by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-166618@lists.php.net to get a copy of this message | ||
Note Submitter: phpzmurf[at]yahoo.com
----
/*
* Parse rss news, quotes etc.
*
* author : phpZmurf <phpzmurf[at]yahoo.com>
* created: 12.04.2007
* ver : 1.0
*
*/
$data = implode("", file("http://feeds.feedburner.com/quotationspage/qotd/"));
$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
xml_parse_into_struct($parser, $data, $values, $tags);
xml_parser_free($parser);
# data saved here
$arrQuotes = array();
# at the beginig - the tag is set colsed
$tagOpen = false;
foreach($values as $key => $item) {
if(!$tagOpen and $item['tag'] == 'item' and $item['type'] ==
'open') {
# item tag opens
$tagOpen = true;
# empty temporary variables
$temp_title = '';
$temp_description = '';
$temp_guid = '';
$temp_link = '';
} elseif($item['tag'] == 'item' and $item['type'] ==
'close') {
# item tag ends
$tagOpen = false;
# if all 4 tags contain data... add them to output array
if($temp_title != '' and $temp_description != '' and $temp_guid !=
'' and $temp_link != '') {
$arrQuotes[] = array(
'title' => $temp_title,
'description' => $temp_description,
'guid' => $temp_guid,
'link' => $temp_link
);
}
} else {
# save data into temporary variables
switch($item['tag']) {
case 'title':
$temp_title = $item['value'];
break;
case 'description':
# this here quz there was a fuggin <p> at the end of the desription
#$temp_description = $item['value'];
$temp_description = substr($item['value'], 0,
strpos($item['value'], '<'));
break;
case 'guid':
$temp_guid = $item['value'];
break;
case 'link':
$temp_link = $item['value'];
break;
default: break;
}
}
}
foreach($arrQuotes as $key => $item) {
print_r($item);
}