Skip to content

Instantly share code, notes, and snippets.

@ivankravchenko
Created May 29, 2014 16:07
Show Gist options
  • Save ivankravchenko/42692d070a0e1c75e824 to your computer and use it in GitHub Desktop.
Save ivankravchenko/42692d070a0e1c75e824 to your computer and use it in GitHub Desktop.
Script for switching WordPress domain. It fixes serialization problems.
#!/usr/bin/php
<?php
$oldDomain = $argv[1];
$domain = $argv[2];
$inputSQL = file_get_contents('php://stdin');
$replacedDomainSQL = str_replace($oldDomain, $domain, $inputSQL);
$fixedSerializeSQL = preg_replace(
'!s:(\d+):"([^"]*?' . preg_quote($domain) . '[^"]*?)";!Ue',
"'s:'.strlen('$2').':\"$2\";'",
$replacedDomainSQL
);
echo $fixedSerializeSQL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment