PHP code example of phine / phar-replace

1. Go to this page and download the library: Download phine/phar-replace library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

phine / phar-replace example snippets


use Phine\Phar\Builder;
use Phine\Phar\Replace\ReplaceObserver;

// create the archive builder
$builder = Builder::create('example.phar');

// create the replace observer
$observer = new ReplaceObserver(
    array(
        'search' => 'replace',
        '@search@' => 'replace',
        '{{ search }}' => 'replace',
        // ...etc...
    )
);

// register it with the builder subjects
$builder->observe(Builder::ADD_FILE, $observer);
$builder->observe(Builder::ADD_STRING, $observer);

// add a value
$observer->setSearchValue('search string', 'replacement value');

// replace a value
$observer->setSearchValue('search string', 'a different value');

// replace all search strings and their values
$observer->setSearchValues(
    array(
        'search' => 'replace',
        '@search@' => 'replace',
        '{{ search }}' => 'replace',
        // ...etc...
    )
);