本文整理汇总了PHP中RSS::recode方法的典型用法代码示例。如果您正苦于以下问题:PHP RSS::recode方法的具体用法?PHP RSS::recode怎么用?PHP RSS::recode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RSS
的用法示例。
在下文中一共展示了RSS::recode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parse
public static function parse($source, $url, $more)
{
$source = str_replace('$', '$', $source);
//try to get encoding of RSS
if (preg_match('/<?xml.*encoding=[\'"](.*?)[\'"].*?>/m', $source, $m)) {
$in_enc = strtoupper($m[1]);
} else {
$in_enc = 'UTF-8';
}
//default encoding is utf-8
//change encoding if it's needed
$source = RSS::recode($in_enc, $modx->config['modx_charset'], $source);
//Collect data about feeed
$feed_title = RSS::find_tag($source, 'title');
$feed_link = RSS::find_tag($source, 'link');
$feed_description = RSS::find_tag($source, 'description');
#RSS::_log("$feed_title | $feed_link | $feed_description");
//parse items
preg_match_all('/<item[^>]*>(.*?)<\\/item>/ism', $source, $items);
$items = $items[1];
/*******************\
<link>link to item</link>
<title>Title of item</title>
<pubDate>Fri, 01 Apr 2011 14:13:08 +0400</pubDate>
<description><![CDATA[Text of item]]></description>
\*******************/
$outputs = array();
//walk on items
for ($i = 0; $i < count($items); $i++) {
$item = $items[$i];
//Collect data
$link = RSS::find_tag($item, 'link');
$title = RSS::find_tag($item, 'title');
$date = RSS::find_tag($item, 'pubdate');
$text = RSS::find_tag($item, 'description');
//clear CDATA
$text = preg_replace('/(<!\\[CDATA\\[|\\]\\]>)/i', '', $text);
//Escape MODx specials
$from = array('{', '}', '[', ']');
$to = array('{', '}', '[', ']');
$text = str_replace($from, $to, $text);
$param = array('link' => $link, 'title' => $title, 'date' => $date, 'text' => $text, 'more' => $more, 'feed_title' => $feed_title, 'feed_link' => $feed_link, 'feed_description' => $feed_description);
array_push($outputs, $param);
}
return $outputs;
}