You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

88 lines
1.6 KiB

  1. <?php
  2. /*
  3. Author:zs
  4. Compeny:Spiders Travel
  5. */
  6. //xml to array
  7. function xml_to_array($xml)
  8. {
  9. $ob = simplexml_load_string($xml);
  10. $json = json_encode($ob);
  11. $array = json_decode($json, true);
  12. return $array;
  13. }
  14. //array to xml
  15. function array_to_xml($array)
  16. {
  17. $xml = "<?xml version='1.0' ?>"."<br>";
  18. function create($array){
  19. $xml = "";
  20. foreach ($array as $k => $v) {
  21. $xml .= "<".$k.">";
  22. if(is_array($v)){
  23. $a = create($v);
  24. $xml.= $a."</".$k.">";
  25. }else{
  26. $xml.= $v."</".$k.">";
  27. }
  28. }
  29. return $xml;
  30. }
  31. $xml = $xml.create($array);
  32. return $xml;
  33. }
  34. //生成txt文件
  35. function create_txt($str){
  36. if (!file_exists('txt'))
  37. {
  38. mkdir ("txt");
  39. }
  40. $time = time();
  41. $txt = "txt/".$time.".txt";
  42. $fb = fopen($txt,'w');
  43. fwrite($fb,$str);
  44. fclose($fb);
  45. }
  46. //压缩文件
  47. function to_zip($path,$file){
  48. $zip=new ZipArchive();
  49. if($zip->open($path, ZipArchive::OVERWRITE) === true){//ZipArchive::OVERWRITE
  50. addFileToZip($file, $zip); //调用方法,对要打包的根目录进行操作,并将ZipArchive的对象传递给方法
  51. $zip->close(); //关闭处理的zip文件
  52. }
  53. function addFileToZip($path,$zip){
  54. $handler=opendir($path); //打开当前文件夹由$path指定。
  55. while(($filename=readdir($handler))!== false){
  56. if($filename != "." && $filename != ".."){//文件夹文件名字为'.'和‘..’,不要对他们进行操作
  57. if(is_dir($path."/".$filename)){// 如果读取的某个对象是文件夹,则递归
  58. addFileToZip($path."/".$filename, $zip);
  59. }else{ //将文件加入zip对象
  60. $zip->addFile($path."/".$filename);
  61. }
  62. }
  63. }
  64. @closedir($path);
  65. }
  66. }
  67. ?>