Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. <?php
  2. $arr = [];
  3. $depths = [];
  4. $ids = [];
  5. function my_comparator($a, $b)
  6. {
  7. {
  8. return ( (0 + $a['LEFT_MARGIN']) - ( 0 +$b['LEFT_MARGIN']));
  9. }
  10. }
  11. function my_decoder($file_path)
  12. {
  13. $i = -1;
  14. if ($file = fopen($file_path, "r")) { //создание потока из файла на чтение
  15. while(!feof($file))
  16. {
  17. $line = fgets($file);
  18. if (substr_count($line, "Array"))
  19. {
  20. $i++;
  21. continue;
  22. }
  23. elseif (substr_count($line, '(') or substr_count($line, ')'))
  24. {
  25. continue;
  26. }
  27. //elseif (substr_count($line, "LEFT_MARGIN")) {
  28. $searcharr = ['>', '[', ']', ' ', '\r', '\n'];
  29. $line = trim($line = str_replace($searcharr, '', $line));
  30. global $arr;
  31. parse_str($line, $arr[$i][]);
  32. // }
  33. }
  34. global $arr;
  35. for($i = 0; $i < count($arr); $i++)
  36. {
  37. for($k = $i + 1; $k < count($arr); $k++)
  38. {
  39. if ($arr[$i][8]['LEFT_MARGIN'] > $arr[$k][8]['LEFT_MARGIN'])
  40. {
  41. $var = $arr[$k];
  42. $arr[$k] = $arr[$i];
  43. $arr[$i] = $var;
  44. }
  45. }
  46. }
  47. fclose($file);
  48. }
  49. }
  50. $temp = "C:\Users\ykouc\Downloads\array.txt";
  51. my_decoder($temp);
  52. global $arr;
  53. for ($i = 0; $i < count($arr);$i++)
  54. {
  55. for ($j = 1; $j < (int)$arr[$i][6]['DEPTH_LEVEL'];$j++)
  56. {
  57. printf(" ");
  58. }
  59. printf("%s \n", $arr[$i][4]['NAME']);
  60. }
  61. echo 1;
  62. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement