需要 php 帮助,博主 api/xml 警告吗?

发布于 2024-08-02 23:30:22 字数 4245 浏览 6 评论 0原文

我遇到了一个脚本来显示我的博客帐户中最后 X 篇博文,但是我收到了此警告:

警告:调用时按引用传递已被弃用 - 按值传递参数;如果您想通过引用传递它,请修改 xml_set_object() 的声明。如果您想启用调用时间按引用传递,可以在 INI 文件中将allow_call_time_pass_reference 设置为 true。然而,未来的版本可能不再支持这一点。在 test.php 的第 88 行,

这是代码:

<div id="latestentries">
  <ul id="entrieslist">
    <?php

    class RSSParser {

        var $insideitem = false;
        var $tag = "";
        var $title = "";
        var $pubDate = "";
        var $link = "";
        var $thr = "";
        var $counter = 1;

        function startElement($parser, $tagName, $attrs) {
            if ($this->insideitem) {
                $this->tag = $tagName;
            } elseif ($tagName == "ITEM") {
                $this->insideitem = true;

            }
        }

        function endElement($parser, $tagName) {
            if ($this->counter < 5) {
                if ($tagName == "ITEM") {
                    $title = htmlspecialchars(trim($this->title));
                        if (strlen($title) > 35) {
                            if ($this->thr > 0) {
                                $name = $title;
                                $name = $name . " "; 
                                $name = substr($name,0,31);
                                $title = $name . " ..."; 
                            }
                            if (strlen($title) > 45) {
                                if ($this->thr == 0) {
                                    $name2 = $title;
                                    $name2 = $name2 . " "; 
                                    $name2 = substr($name2,0,41);
                                    $title = $name2 . "..."; 
                                }
                            }
                        }
                    $date = htmlspecialchars(trim($this->pubDate));
                    $pubDate = substr($date,0,str_length-20) . ".";
                    printf("<li class='entry'><a href='%s'><span class='entrydate'>%s</span><span>%s</span>",trim($this->link),$pubDate,$title);
                        if ($this->thr == 1) { printf("<span class='entrycomments'>(%s Comment)</span>",$this->thr); }
                        elseif ($this->thr > 1) { printf("<span class='entrycomments'>(%s Comments)</span>",$this->thr); }
                    echo "</a></li>";   
                    $counter = $this->counter;
                    $this->counter = $counter + 1;
                    $this->title = "";
                    $this->pubDate = "";
                    $this->link = "";
                    $this->thr = "";
                    $this->insideitem = false;
                }
            }
        }

        function characterData($parser, $data) {
            if ($this->insideitem) {
            switch ($this->tag) {
                case "TITLE":
                $this->title .= $data;
                $this->counter .= $counter;
                break;
                case "PUBDATE":
                $counter++;
                $this->pubDate .= $data;
                break;
                case "LINK":
                $counter++;
                $this->link .= $data;
                break;
                case "THR:TOTAL":
                $counter++;
                $this->thr .= $data;
                break;
            }
            }
        }
    }

    $xml_parser = xml_parser_create();
    $rss_parser = new RSSParser();
    xml_set_object($xml_parser,&$rss_parser);
    xml_set_element_handler($xml_parser, "startElement", "endElement");
    xml_set_character_data_handler($xml_parser, "characterData");
    $fp = fopen("rss.xml","r")
        or die("Error reading RSS data.");
    while ($data = fread($fp, 4096))
        xml_parse($xml_parser, $data, feof($fp))
            or die(sprintf("XML error: %s at line %d", 
                xml_error_string(xml_get_error_code($xml_parser)), 
                xml_get_current_line_number($xml_parser)));
    fclose($fp);
    xml_parser_free($xml_parser);

    ?>
  </ul>
</div>

有人可以帮我关闭警告,或者告诉我如何修复它吗? :)

I came across a script to display the last X amount of blog posts from my blogger account, however I'm getting this warning:

Warning: Call-time pass-by-reference has been deprecated - argument passed by value; If you would like to pass it by reference, modify the declaration of xml_set_object(). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file. However, future versions may not support this any longer. in test.php on line 88

Here's the code:

<div id="latestentries">
  <ul id="entrieslist">
    <?php

    class RSSParser {

        var $insideitem = false;
        var $tag = "";
        var $title = "";
        var $pubDate = "";
        var $link = "";
        var $thr = "";
        var $counter = 1;

        function startElement($parser, $tagName, $attrs) {
            if ($this->insideitem) {
                $this->tag = $tagName;
            } elseif ($tagName == "ITEM") {
                $this->insideitem = true;

            }
        }

        function endElement($parser, $tagName) {
            if ($this->counter < 5) {
                if ($tagName == "ITEM") {
                    $title = htmlspecialchars(trim($this->title));
                        if (strlen($title) > 35) {
                            if ($this->thr > 0) {
                                $name = $title;
                                $name = $name . " "; 
                                $name = substr($name,0,31);
                                $title = $name . " ..."; 
                            }
                            if (strlen($title) > 45) {
                                if ($this->thr == 0) {
                                    $name2 = $title;
                                    $name2 = $name2 . " "; 
                                    $name2 = substr($name2,0,41);
                                    $title = $name2 . "..."; 
                                }
                            }
                        }
                    $date = htmlspecialchars(trim($this->pubDate));
                    $pubDate = substr($date,0,str_length-20) . ".";
                    printf("<li class='entry'><a href='%s'><span class='entrydate'>%s</span><span>%s</span>",trim($this->link),$pubDate,$title);
                        if ($this->thr == 1) { printf("<span class='entrycomments'>(%s Comment)</span>",$this->thr); }
                        elseif ($this->thr > 1) { printf("<span class='entrycomments'>(%s Comments)</span>",$this->thr); }
                    echo "</a></li>";   
                    $counter = $this->counter;
                    $this->counter = $counter + 1;
                    $this->title = "";
                    $this->pubDate = "";
                    $this->link = "";
                    $this->thr = "";
                    $this->insideitem = false;
                }
            }
        }

        function characterData($parser, $data) {
            if ($this->insideitem) {
            switch ($this->tag) {
                case "TITLE":
                $this->title .= $data;
                $this->counter .= $counter;
                break;
                case "PUBDATE":
                $counter++;
                $this->pubDate .= $data;
                break;
                case "LINK":
                $counter++;
                $this->link .= $data;
                break;
                case "THR:TOTAL":
                $counter++;
                $this->thr .= $data;
                break;
            }
            }
        }
    }

    $xml_parser = xml_parser_create();
    $rss_parser = new RSSParser();
    xml_set_object($xml_parser,&$rss_parser);
    xml_set_element_handler($xml_parser, "startElement", "endElement");
    xml_set_character_data_handler($xml_parser, "characterData");
    $fp = fopen("rss.xml","r")
        or die("Error reading RSS data.");
    while ($data = fread($fp, 4096))
        xml_parse($xml_parser, $data, feof($fp))
            or die(sprintf("XML error: %s at line %d", 
                xml_error_string(xml_get_error_code($xml_parser)), 
                xml_get_current_line_number($xml_parser)));
    fclose($fp);
    xml_parser_free($xml_parser);

    ?>
  </ul>
</div>

Could someone help me turn off the warning, or show me how to fix it? :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

反目相谮 2024-08-09 23:30:22

去掉“&”在 $rss_parser 中:

xml_set_object($xml_parser,&$rss_parser);

变为:
xml_set_object($xml_parser,$rss_parser);

根本不需要通过引用传递对象。在这个版本的 PHP 中它是自动的。

雅各布

Get rid of the "&" in $rss_parser:

xml_set_object($xml_parser,&$rss_parser);

Becomes:
xml_set_object($xml_parser,$rss_parser);

Passing the object by reference should not be needed at all. It is automatic in this version of PHP.

Jacob

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文