Advertisement
Fryziu

Untitled

Mar 18th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.76 KB | None | 0 0
  1. <?php
  2. $path_file = 'file.txt';
  3. $file_contents = file_get_contents($path_file);
  4. $path_json = 'array.json';
  5. $read_json = file_get_contents( $path_json );
  6. $array_json = json_decode( $read_json, true );
  7.  
  8. $data=$array_json;
  9. function batchChange( $data, $level)  
  10. {  
  11.     global $file_contents;
  12.     foreach( $data as $key1 => $value1 )
  13.     {
  14.         $file_contents = str_replace($key1,$value1,$file_contents);
  15.         echo $file_contents .  "<br />";
  16.     }    
  17. }
  18.  
  19. echo "<pre>";
  20. batchChange( $data, 0 );
  21. echo "</pre>";
  22. file_put_contents("file_new.txt",$file_contents); // write permissions !
  23.  
  24. // file.txt looks like this
  25. old red dry shoe
  26.  
  27. // array.json looks like this
  28. {  
  29.     "old": "new",
  30.     "red": "blue",
  31.     "dry": "wet",
  32.     "shoe": "hat"
  33. }
  34.  
  35. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement