如何在函数内调用DOMDocument的getNamedItem()和nodeValue()

时间:2015-11-07 13:22:59

标签: domdocument nodevalue

我有一个使用DOMDocument导入的XML。为了避免很多foreach循环用于retreive nodeValue(),我将它用作单独的函数。它在实时服务器中对我不起作用。功能如下:

        <?php
    function Single_ParseDomObjXML($parameter){
          $value='';
          foreach($parameter as $get_val)
            {
                $value=$get_val->nodeValue;
            }
            return $value;
      }

    $text_tags=$events->getElementsByTagName('text');
                    foreach($text_tags as $text_inf){
                        $event['text']['promo']=Single_ParseDomObjXML($text_inf->getElementsByTagName('promo'));
                        $event['text']['spec']=Single_ParseDomObjXML($text_inf->getElementsByTagName('spec'));
                        $event['event_desc']=nl2br(Single_ParseDomObjXML($text_inf->getElementsByTagName('desc')));
                    }
?>

0 个答案:

没有答案