Guest User

Untitled

a guest
Feb 22nd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. <?php
  2.  
  3. $dir = "hints/";
  4. $file = $file . '.xml';
  5. $file = $dir.$file;
  6. // if ( !isset($file) )
  7. // {
  8. // $file = "force_quit.xml";
  9. // }
  10. $xmlParser = xml_parser_create();
  11. $params = array();
  12. $level = array();
  13.  
  14. $openFile = fopen($file, "r");
  15. if (!$openFile) {
  16. echo $error = "<span class=\"error\">Couldn't open the file for reading</span>";
  17. die;
  18. }
  19.  
  20. $data = fread($openFile, filesize($file));
  21. fclose($openFile);
  22. xml_parse_into_struct($xmlParser, $data, $vals, $index);
  23. xml_parser_free($xmlParser);
  24.  
  25.  
  26.  
  27. foreach( $vals as $xmlElement )
  28. {
  29. if ( $xmlElement['type'] == "open" )
  30. {
  31. if ( array_key_exists("attributes", $xmlElement) )
  32. {
  33. list( $level [$xmlElement['level']], $extra) = array_values( $xmlElement['attributes'] );
  34. } else
  35. {
  36. $level[$xmlElement['level']] = $xmlElement['tag'];
  37. }
  38. }
  39. if ( $xmlElement['type'] == 'complete' )
  40. {
  41. $start_level = 1;
  42. $php_stmt = '$params';
  43. while ( $start_level < $xmlElement['level'] )
  44. {
  45. $php_stmt .= '[strtolower($level[' . $start_level . '])]';
  46. $start_level++;
  47. }
  48. $php_stmt .= '[strtolower($xmlElement[\'tag\'])] = $xmlElement[\'value\'];';
  49. eval($php_stmt);
  50. }
  51. }
  52.  
  53. ?>
Add Comment
Please, Sign In to add comment