您好,欢迎访问一九零五行业门户网

php中的关于xml的使用(SEO)

关于xml使用,这个地方是为了seo收录写的两个函数,仅供参考,欢迎交流,有问题欢迎提问,具体的函数可以查文档。
functionedit_xml_file($xml_file_path,$datas,$is_index = false,$is_compress = true){$doc = new domdocument('1.0', 'utf-8'); $doc->formatoutput = true; $flag = false; if( !@file_exists($xml_file_path) || !$doc->load($xml_file_path)) { $flag = create_xml_file($xml_file_path,$datas,$is_index,$is_compress); return$flag; } //读取文件数据$xmldata = simplexml_load_file($xml_file_path); $newxmldata = array(); $xml_url = array(); foreach ($xmldataas$key=>$obj){ $obj = (array) $obj; if(isset($obj['lastmod'])){ $obj['lastmod'] = date('c',time()); } $xml_url[] = $obj['loc']; $newxmldata[][$key] = $obj; } //将新添加的数据放在一起foreach ($datasas$data){ if(!in_array($data[$key]['loc'], $xml_url)){ $newxmldata[] = $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,追加数据 * @param xml_file_path 文件路径,$data 数据,$is_index 为了区分是地图文件还是地图索引,默认是地图文件 * @author zdj * @date 2015-01-23 */functionadd_data_xml_file($xml_file_path,$datas,$is_index = false,$is_compress = true){$doc = new domdocument('1.0', 'utf-8'); $doc->formatoutput = true; $flag = false; if( !@file_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 ($datasas$data){ foreach ($dataas$key=>$obj){ $key_dom = $doc->createelement($key); foreach ($objas$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); //创建压缩的文件$xml_gz_file_path = $xml_file_path.'.gz'; if($is_compress){ $fp = gzopen ($xml_gz_file_path, 'w9'); gzwrite ($fp, $doc->savexml()); gzclose($fp); } //给文件赋予权限//给文件赋予权限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);}
版权声明:本文为博主原创文章,未经博主允许不得转载。
以上就介绍了php中的关于xml的使用(seo),包括了方面的内容,希望对php教程有兴趣的朋友有所帮助。
其它类似信息

推荐信息