The use of XML in PHP (SEO)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.