When you’re migrating WordPress (or any other platform using serialized PHP strings in the database) between domains, you must use a safe search and replace method that preserves the integrity of the serialized string lengths. A simple of a dump file for http://localhost to, for example, http://thenewdomain.com is problematic because the length of the string changes but the indexes for the serialized strings does not. Consequently settings are lost and widgets disappear. Not good.
This script can now also handle multiply nested serializations, which can happen in transient values in WP at times, and it can also handle multi-byte Unicode changes safely. This is important now that internationalised domain names are allowed.
It’s worth mentioning that the code will work for any platform that stores PHP serialized arrays in a MySQL database. You can easily use this script on Drupal, Joomla and many other systems where you need to change items across a database without messing up your stored arrays.
How to Move WordPress to a New Server (without losing