atomrus1993

Untitled

Jan 16th, 2017
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.94 KB | None | 0 0
  1. <?php
  2. include 'db.php';
  3. $file = simplexml_load_file("file.xml");
  4.  
  5. // substr('asshole', 0, -1) обрезать последний символ !!!!
  6.  
  7. function parser ($par1){
  8.     global $file;
  9.     if($par1!='readinesses'){
  10.         $par2 = substr($par1, 0, -1);
  11.     }else{
  12.         $par2 = substr($par1, 0, -2);
  13.     }
  14.     $parser = $file->$par1->$par2;
  15.     foreach ($parser as $out) {
  16.         $id = $out['id'];
  17.         $title = $out['title'];
  18.         $result = mysql_query("INSERT INTO  `he78parse`.`{$par1}` (`id` ,`title`) VALUES ('$id', '$title')");
  19.     }
  20.     if($result==1){echo "Операция выполнена успешно<br/>";}else{echo "Не удачно<br/>";}
  21. }
  22.  
  23. parser("builders");
  24. parser("townareas");
  25. parser("streets");
  26. parser("metros");
  27. parser("readinesses");
  28. parser("buildingTypes");
  29. parser("facings");
  30. parser("apartmentTypes");
  31. parser("roomNumbers");
  32.  
  33. // $data = parser("townareas","townarea");
  34. // echo $data;
  35.  
  36.  
  37. ?>
Advertisement
Add Comment
Please, Sign In to add comment