mescalito88

mescalito88
Рейтинг
41
Регистрация
04.11.2006
Должность
делаю фирмы однодневки

развлекалово - это думаю понятно, а галеры - это галереи "для взрослых" :)

Код rss.php :


<?
// Класс для работы с RSS
// Alexander S Kostestky ( alexk-at-flashmaster-ru )

class rss{
// Переменные класса
var $sUrl;
var $sBuff;
var $rXml_parser;
var $aParentField;
var $aCurrrentField;
var $aCurrentNamespace;
var $aRss;
var $aItems;
var $aChannel;
// Конструктор класса
function rss($url=""){
if(!isset($url) || empty($url)){
echo "no RSS url";
exit();
}
// Инициализация переменных
$this->aChannel = array();
$this->aItems = array();
$this->aRss = array($this->aChannel, $this->aItems);
$this->aParentField = array();
$this->xml_parser = undef;
$this->sUrl = strval($url);
// Метод запроса RSS документа
$this->GetUrl();
// Метод разбора RSS документа
$this->ParseRss();
}
// Метод запроса RSS документа
function GetUrl(){
set_time_limit(0);
$this->sBuff = join ("", file($this->sUrl));
//echo $this->sBuff."\n\n<hr>";
}
// Метод разбора RSS документа
function ParseRss(){
$this->rXml_parser = xml_parser_create();
xml_set_object($this->rXml_parser, &$this);
xml_set_element_handler($this->rXml_parser, "starttag", "endtag");
xml_set_character_data_handler($this->rXml_parser, "cdata");
if (!xml_parse($this->rXml_parser, $this->sBuff)) {
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($this->rXml_parser)),
xml_get_current_line_number($this->rXml_parser))
);
}
xml_parser_free($this->rXml_parser);
$this->aRss = array("channel" => $this->aChannel, "items" => $this->aItems);
}
/*
/ Метод GetArrayRss
/ @return массив с данными - результат разбора всего RSS документа
*/
function GetArrayRss(){
return $this->aRss;
}
/*
/ Метод GetChannelVal
/ @return строка с данными одного поля из ветки channel
*/
function GetChannelVal($sVal){
return $this->aChannel[$sVal];
}
/*
/ Метод GetArrayChannel
/ @return массив с данными ветки channel
*/
function GetArrayChannel(){
return $this->aChannel;
}
/*
/ Метод GetArrayItem
/ @return массив с данными ветки item
*/
function GetArrayItem(){
return $this->aItems;
}
/*
/ Метод starttag
/ Метод разбора открывающихся тегов в RSS документе
/ @return void
*/
function starttag($rXml_parser, $tag, $attributes){
$tag = strtolower( $tag );
$namespace = false;
if ( strpos( $tag, ':' ) ) {
list($namespace, $tag) = split( ':', $tag, 2);
}
$this->aCurrrentField = $tag;
if ( $namespace and $namespace != 'rdf' ) {
$this->aCurrentNamespace = $namespace;
}
if ( $tag == 'channel' ) {
array_unshift( $this->aParentField, 'channel' );
}elseif ( $tag == 'items' ) {
array_unshift( $this->aParentField, 'items' );
}elseif ( $tag == 'item' ){
array_unshift( $this->aParentField, 'item' );
}elseif ( $tag == 'cdatainput' ) {
array_unshift( $this->aParentField, 'cdatainput' );
}elseif ( $tag == 'image' ) {
array_unshift( $this->aParentField, 'image' );
}
}
/*
/ Метод endtag
/ Метод разбора закрывающихся тегов в RSS документе
/ @return void
*/
function endtag($rXml_parser, $tag){
$tag = strtolower($tag);
if ( $tag == 'item' ) {
$this->aItems[] = $this->current_item;
$this->current_item = array();
array_shift( $this->aParentField );
}elseif ( $tag == 'channel' or $tag == 'items' or $tag == 'cdatainput' or $tag == 'image' ) {
array_shift( $this->aParentField );
}
$this->aCurrrentField = '';
$this->aCurrentNamespace = false;
}
/*
/ Метод cdata
/ Метод разбор данных между открывающимися и закрывающимися тегами
/ @return void
*/
function cdata($rXml_parser, $cdata){
if ( $this->aParentField[0] == $this->aCurrrentField || !$this->aCurrrentField ){
return;
}elseif ( $this->aParentField[0] == 'channel') {
if ( $this->aCurrentNamespace ) {
$this->aChannel[ $this->aCurrentNamespace ][ $this->aCurrrentField ] .= $cdata;
}else{
$this->aChannel[ $this->aCurrrentField ] .= $cdata;
}
}elseif ( $this->aParentField[0] == 'item' ){
if ( $this->aCurrentNamespace ) {
$this->current_item[ $this->aCurrentNamespace ][ $this->aCurrrentField ] .= $cdata;
}else{
$this->current_item[ $this->aCurrrentField ] .= $cdata;
}
}elseif ( $this->aParentField[0] == 'cdatainput' ) {
if ( $this->aCurrentNamespace ) {
$this->cdatainput[ $this->aCurrentNamespace ][ $this->aCurrrentField ] .= $cdata;
}else{
$this->cdatainput[ $this->aCurrrentField ] .= $cdata;
}
}elseif ( $this->aParentField[0] == 'image' ) {
if ( $this->aCurrentNamespace ) {
$this->image[ $this->aCurrentNamespace ][ $this->aCurrrentField ] .= $cdata;
}else{
$this->image[ $this->aCurrrentField ] .= $cdata;
}
}
}
}
?>

Код вывода текста:


<?
require("rss.php");
$rssurl = "http://news.yandex.ru/software.rss";
$cRss = new rss($rssurl);
$item = $cRss->GetArrayItem();
for($i=0;$i<count($item);$i++)
{
if(!$item[$i]) break;
$url = $item[$i]['link'];
echo "<a href=\"/news/".($i+1)."/\" title=\"".$item[$i]['title']."\"><B>".$item[$i]['title']."</B></a><BR>";
}
?>
Gregor25:
неее в Орджо хорошее ;) водичка почище и места похолмистей, а насчет темы лучше поспрашивайте на feo.ru или kafa-info.com (там тоже есть форум) или пойдите в приватбанк (в конце набережной вверх до кинотеатра Украина) откройте карту миттеву (правда не знаю откроют ли ее нерезиденту) и выведети гривны на нее прям с ВМкипера, 1-3 суток и деньга в кармане

Орджо супер, + в Новом Свете очень нравиться 😎

по теме: www.kafa.crimea.ua

Базы дохнут очень быстро, искать самому надо, от заспамленых толку нуль.

Всего: 184