Skip to content

Instantly share code, notes, and snippets.

@ahawthorne
Created October 23, 2012 17:37
Show Gist options
  • Select an option

  • Save ahawthorne/3940260 to your computer and use it in GitHub Desktop.

Select an option

Save ahawthorne/3940260 to your computer and use it in GitHub Desktop.
search and replace, recalculate string-length in serialized array
<?php
$in = file_get_contents('input.sql');
// change domain(s)
$in = preg_replace('/old.example.com/', 'new.example.com', $in);
$in = preg_replace('/older.example.com/', 'newer.example.com', $in);
// recalculate string lengths in serialized arrays
$out = preg_replace('/s:(\d+):\\\"(.*?)\\\";/e', "'s:'.strlen('$2').':\"$2\";'", $in);
file_put_contents('output.sql', $out);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment