0
public function action_xmlread()
{
        $xml = simplexml_load_file('new.xml');

        foreach($xml->body as $b)
        {
            foreach ($b->node as $node) {
                $this->dig($node);
            }
        }
}
public function dig($node)
{
    if(isset($node->tit) && !isset($node->url))
    {
        $this->dig($node);
    }else{
        $this->grabData($node);
    }
}
public function grabData($node)
{
    $category_names = array('userdef1', 'userdef2');

    $url = $node->url;

    $category = '';
    foreach($category_names as $catname)
    {
        if(isset($node->$catname))
        {
            $category = $node->$catname;

            break;
        }
    }

    $keywords = $node->key;
    $title = $node->tit;
    if(empty($url) && empty($category))
    {
        continue;
    }
    $this->saveItem($title, $url, $category, $keywords);
    echo $url . " , category: ". $category;
    echo '<br />';
}

当我运行 xmlread() 它死了:

已达到“100”的最大函数嵌套级别,正在中止!

$this->dig($node); 

在 dig() 函数内部..如何解决?

4

2 回答 2

2

您处于无限递归中,因为您没有更改传递给的参数dig。也许您必须传递子节点?

于 2012-05-09T19:58:54.583 回答
1

要增加函数嵌套级别,您需要编辑 php.ini。但也许你的问题出在其他地方。

xdebug.max_nesting_level = 200

来源

于 2012-05-09T20:01:07.750 回答