Avoid DOMDocument XML warnings in php

前端 未结 3 2034
悲&欢浪女
悲&欢浪女 2020-12-10 04:57

I\'m fetching xml files from a server and sometimes I\'m getting a non-valid xml files, because of this I\'m getting a warning:

Warning: DOMDocument::load()          


        
3条回答
  •  醉梦人生
    2020-12-10 05:31

    Turn off strict error checking:

    $dom = new DOMDocument();
    $dom->strictErrorChecking = FALSE ;
    
    $dom->load('/path/to/file.xml');
    if (!$dom->validate()) {
       // Invalid XML!
    }
    

提交回复
热议问题