About the use of XML, this place is for the SEO included write two functions, only for reference, welcome to communicate, have questions welcome questions, specific functions can check the document.
function edit_xml_file($xml _file_path,$datas,$is _index = False,$is _compress = True){ $doc=NewDomDocument (' 1.0 ',' Utf-8 ');$doc->formatoutput =true;$flag=false;if([Email Protected]_exists ($xml _file_path) || !$doc->load ($xml _file_path)) {$flag= Create_xml_file ($xml _file_path,$datas,$is _index,$is _compress);return $flag; }//Read file data $xmldata= Simplexml_load_file ($xml _file_path);$newxmldata=Array();$xmL _url=Array();foreach($xmldata as $key=$obj){$obj= (Array)$obj;if(isset($obj[' Lastmod '])){$obj[' Lastmod '] = Date (' C ', time ()); }$xmL _url[] =$obj[' Loc '];$newxmldata[][$key] =$obj; }//Put the newly added data together foreach($datas as $data){if(!in_array ($data[$key][' Loc '],$xmL _url)){$newxmldata[] =$data; } }//re-update created files based on new data if(!Empty($newxmldata) && Unlink ($xml _file_path)){$flag= Create_xml_file ($xml _file_path,$newxmldata,$is _index,$is _compress); }unset($datas);return $flag;}/** XML, append data * @param xml_file_path file path, $data data, $is _index in order to differentiate between a map file or a map index, the default is a map file * @author ZDJ * @date 2015-01-23 * * function add_data_xml_file($xml _file_path,$datas,$is _index = False,$is _compress = True){ $doc=NewDomDocument (' 1.0 ',' Utf-8 ');$doc->formatoutput =true;$flag=false;if([Email Protected]_exists ($xml _file_path) || !$doc->load ($xml _file_path)) {$flag= Create_xml_file ($xml _file_path,$datas,$is _index,$is _compress);return $flag; }$root=$doc->documentelement;foreach($datas as $data){foreach($data as $key=$obj){$key _dom=$doc->createelement ($key);foreach($obj as $attribute=$attribute _value){$attribute _dom=$doc->createelement ($attribute);$attribute _dom_value=$doc->createtextnode ($attribute _value);$attribute _dom->appendchild ($attribute _dom_value);$key _dom->appendchild ($attribute _dom); }$root->appendchild ($key _dom); } }$doc->appendchild ($root);$doc->save ($xml _file_path);//Create a compressed file $xml _gz_file_path=$xml _file_path.'. Gz ';if($is _compress){$fp= Gzopen ($xml _gz_file_path,' W9 '); Gzwrite ($fp,$doc->savexml ()); Gzclose ($fp); }//assigning permissions to files//granting permissions to files if(File_exists ($xml _file_path) {chmod ($xml _file_path,0744); }if(File_exists ($xml _gz_file_path) {chmod ($xml _gz_file_path,0744); }unset($datas);}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The use of XML in PHP (SEO)