Skip to content

AlextheYounga/php-search-replace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP Search & Replace (Core Logic)

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.

Usage

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'],
    ],
);

What This Is Not

  • 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.

Fixtures & Parity

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.

Running Tests

composer install
./vendor/bin/phpunit

Credits

License

Released under the MIT License.

About

A PHP equivalent to Automattic's go-search-replace

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages