Php 正在分析rss-未定义的偏移量0

Php 正在分析rss-未定义的偏移量0,php,regex,parsing,rss,Php,Regex,Parsing,Rss,我有一个rss解析代码,但在第38行收到了关于未定义偏移量0的错误消息($$row=$preg_match[1][0];) 以下是完整的解析代码: <?php echo ' <style> .scores {font-family:"Trebuchet MS",Verdana, Arial, sans-serif; font-size:12px;line-height:140%; } .scores th {background:#6D8D9F; text-align:le

我有一个rss解析代码,但在第38行收到了关于未定义偏移量0的错误消息(
$$row=$preg_match[1][0];

以下是完整的解析代码:

<?php


echo ' <style>
.scores {font-family:"Trebuchet MS",Verdana, Arial, sans-serif; font-size:12px;line-height:140%; }
.scores th {background:#6D8D9F; text-align:left; border:0; color:#fff;padding:2px 5px 2px 5px;}
.scores td {padding:2px 5px 2px 5px; margin:0; border:0;}
.scores td.dark {background:#D1DADF; }
.scores td.bright {background:#E0E8EF; }
.scores a {color:#ccc; text-decoration:none;}
.scores a:hover {color:#fff; text-decoration:none;}
.scores .foot {text-align:center;background:#6D8D9F; color:#ff0000}
.scores .foot small { color:#222}
.scores small {color:#777;}
</style>'."\r\n";



$rss_file = '';
$fp = fsockopen ('www.soccerstats247.com', 80, $errno, $errstr, 5);
if ($fp) {
    fputs ($fp, "GET /CompetitionFeed.aspx?langId=1&leagueId=1204 HTTP/1.0\r\nHost: www.soccerstats247.com\r\n\r\n");
    while (!feof($fp))  {
        $rss_file .= fgets($fp);
    }
    fclose($fp);
} else  {echo('RSS Error :(');}
$rss_rows = array ( "title", "link", "description", "pubDate" );
$rss_array = explode ( "<item>", $rss_file );
echo '<table class="scores"><tr><th> ';
$lineC = 0;
foreach ( $rss_array as $string ) {
    $arrData =array();
    foreach ( $rss_rows as $row ) {
        preg_match_all ( "|<$row>(.*)</$row>|", $string, $preg_match );


        $$row = $preg_match [1] [0];
        $arrData[$row] = $$row;
            }
    $tickerClass = round($lineC/2) == $lineC/2 ? 'dark' : 'bright';
    if (stripos($arrData['description'], 'SoccerStats247'  ) !== false) {
           } else {

               $result = str_replace(array('&lt;br/&gt;&lt;a rel="nofollow" href=""&gt;&lt;/a&gt;'), array(''), $arrData['description']);
    $date = date("Y.m.d", strtotime($arrData['pubDate']));

        echo '<tr><td class="'.$tickerClass.'">'.$date.' '.$result .'<br></td></tr>';
    }
    $lineC++;
}
echo '</table>';

?>


我的问题:为什么我收到错误消息?我的代码有什么问题?非常感谢。

我已经为您测试了代码。如果您在循环中var_转储$preg_匹配,您将看到前3个数组包含提要或网站本身之后的信息。第四个循环只输出一个空数组:

array(2) {
[0] => array(0) { }
[1] => array(0) { }
}
下面是您想要了解的球队和比赛数据的实际阵列。所以是的。基本上,警告表示在数组中没有您正在查找的实际条目

最好的办法是

    if(!empty($preg_match[1]))
    {
            $$row = $preg_match [1] [0];
            $arrData[$row] = $$row;
    }

在您尝试输出或维护数据之前。

在调用该键之前,请检查该键是否存在……谢谢您的回答。现在,我得到了关于array_key_exists()的错误消息,它正好需要2个参数,第53行给出了1个参数。我在输出数据之前添加了if子句。下面是我当前代码的结尾:
$tickerClass=round($lineC/2)==$lineC/2?“暗“:”亮“;if(stripos($arrData['description'],'SoccerStats247')!==false){else{$result=str_replace(数组('br/a rel=“nofollow”href=”“/a'),array(“”),$arrData['description']);$date=date(“Y.m.d”,strotime($arrData['pubDate']);if(数组存在($preg_-match[1][0])){echo'.$date'.$result'.
';}}
Ahhh,我真的很抱歉。我误读了你!我已更改了上面的答案。请尝试检查数组是否为空,而不是检查是否存在特定的数组键。如我的示例所示。