This repository contains a pure PHP port of the core logic that powers Automattic's go-search-replace utility.
It exposes a single class, PhpSearchReplaceHandler, that rewrites chunks of SQL while keeping serialized PHP strings valid. There is no CLI wrapper or WordPress integration here—just the serialization-aware replacement engine extracted for reuse.
This created for the CLI Wordpress helper I created called Movepress.
use PhpSearchReplace\PhpSearchReplaceHandler;
$handler = new PhpSearchReplaceHandler();
$handler->replaceInFile(
inputPath: __DIR__ . '/dump.sql',
outputPath: __DIR__ . '/dump-updated.sql',
replacements: [
['from' => 'http://example.com', 'to' => 'https://example.com'],
['from' => 'wp.example.com', 'to' => 'wp.migration.test'],
],
);- No CLI executable is bundled yet.
- No helper for auto-migrating WordPress configuration; you're expected to wire the service into your own tooling.
- No Composer plugin/installer hooks—this is just a standalone class backed by tests.
tests/Fixtures mirrors the sample cases used by the Go implementation.
PhpSearchReplaceHandlerTest exercises every scenario—including overlapping replacements, heavy escaping, and binary data—to ensure output parity with the upstream tool.
composer install
./vendor/bin/phpunit- Original algorithm & fixtures: Automattic/go-search-replace (MIT)
Released under the MIT License.