Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $path_file = 'file.txt';
- $file_contents = file_get_contents($path_file);
- $path_json = 'array.json';
- $read_json = file_get_contents( $path_json );
- $array_json = json_decode( $read_json, true );
- $data=$array_json;
- function batchChange( $data, $level)
- {
- global $file_contents;
- foreach( $data as $key1 => $value1 )
- {
- $file_contents = str_replace($key1,$value1,$file_contents);
- echo $file_contents . "<br />";
- }
- }
- echo "<pre>";
- batchChange( $data, 0 );
- echo "</pre>";
- file_put_contents("file_new.txt",$file_contents); // write permissions !
- // file.txt looks like this
- old red dry shoe
- // array.json looks like this
- {
- "old": "new",
- "red": "blue",
- "dry": "wet",
- "shoe": "hat"
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement