English 中文(简体)
Parsing RSS, maybe php4->php5 issue?
原标题:Parsing RSS, maybe php4->php5 issue?

A. 长期聆听员

我有这一职能(我不记得,我知道,我是永远的)。

它简单地将XML输入,并编制即将到来的格人名单——它正在做罚款,但正在改用最新的PHP的新服务器,并且是固定的。

    function parseRSS($url) { 

    $feedeed = implode(  , file($url));
    $parser = xml_parser_create();
    xml_parse_into_struct($parser, $feedeed, $valueals, $index);
    xml_parser_free($parser);

    foreach($valueals as $keyey => $valueal){
        if($valueal[ type ] !=  cdata ) {
            $item[$keyey] = $valueal;
        }
    }
    $i = 0;
    foreach($item as $key => $value){
        if($value[ type ] ==  open ) {
            $i++;
            $itemame[$i] = $value[ tag ]; 
        } elseif($value[ type ] ==  close ) {

            $feed = $values[$i];
            $item = $itemame[$i];
            $i--;

            if(count($values[$i])>1){
                $values[$i][$item][] = $feed;
            } else {
                $values[$i][$item] = $feed;
            }
        } else {
            $values[$i][$value[ tag ]] = $value[ value ];  
        }
    }
    return $values[0];
} 

$xml = parseRSS("http://acousti.co/feeds/artist/AboveThem");

$count = 0;

foreach($xml[ RSS ][ CHANNEL ][ ITEM ] as $item) {
        $pubDate = $item[ PUBDATE ];
        $pubDateFormatted = date( D j M Y , strtotime($pubDate));

        echo("<a href="{$item[ LINK ]}" target="_blank" class="indexBoxNews">{$item[ DESCRIPTION ]}{$link}</a>
            <p class="rss-date">$pubDateFormatted</p>");

        if (++$count == 5) break;
}

是否有任何人知道它为什么会停止工作——该守则是在第5段之前写成的,这肯定可能是一个兼容性问题?

Any help very much appreciated :) Rob

最佳回答

既然你现在重新上了第5号计划,你可能想用简单的xml来改写该法典。 PHP4在不增加图书馆的情况下,确实有处理XML的良好方式,但现在使用的是PHP 5,你的代码应当是你用于PHP4的一小部分。

为此:

$xml = simplexml_load_file( http://acousti.co/feeds/artist/AboveThem );

foreach ($xml->channel->item as $item)
{
    $pubDateFormatted = date( D j M Y , strtotime((string) $item->pubDate));
    echo  <a href="  . (string) $item->link .  " target="_blank" class="indexBoxNews">  . (string) $item->description .  </a>
            <p class="rss-date">  . $pubDateFormatted .  </p> ;
}
问题回答

确保在新的服务器上安装PHP“allow_url_f open”一字,否则文档($url)赢得t work

http://gr.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签