Remove namespace from XML using PHP

前端 未结 4 1430
你的背包
你的背包 2020-12-05 19:15

I have an XML document that looks like this:



        
4条回答
  •  孤街浪徒
    2020-12-05 19:51

    I found the answer above to be helpful, but it didn't quite work for me. This ended up working better:

    // Gets rid of all namespace definitions 
    $xml_string = preg_replace('/xmlns[^=]*="[^"]*"/i', '', $xml_string);
    
    // Gets rid of all namespace references
    $xml_string = preg_replace('/[a-zA-Z]+:([a-zA-Z]+[=>])/', '$1', $xml_string);
    

提交回复
热议问题