Skip to content

Instantly share code, notes, and snippets.

@w00fz
Created May 29, 2015 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save w00fz/283ff4a95db70778beec to your computer and use it in GitHub Desktop.
Save w00fz/283ff4a95db70778beec to your computer and use it in GitHub Desktop.
<?php
$file = file_get_contents('file.json');
$count = -1;
preg_match_all("/(?:color:\s'([^']+)')/i", $file, $colors);
preg_match_all("/(?:windows:\s'([^']+)')/i", $file, $windows);
$file = preg_replace_callback("/(?:url:\s'([^']+)')/i", function($matches) use (&$count, $colors, $windows) {
$count++;
return "url: '". $matches[1] . $colors[1][$count] . '-' . $windows[1][$count] . ".jpg'";
}, $file);
file_put_contents('file-replaced.json', $file);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment