PHP code example of friedolinfoerder / html-changer

1. Go to this page and download the library: Download friedolinfoerder/html-changer 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/ */

    

friedolinfoerder / html-changer example snippets


use html_changer\HtmlChanger

// parse html
$htmlChanger = new HtmlChanger($html);

// search and replace text
$htmlChanger = new HtmlChanger($text, [
    'search' => [
        'test' => [
            'value' => 'TEST', 
            'caseInsensitive' => false, // default false
            'wordBoundary' => true, // default true
            'group' => 1, // default is the key (here 'test') 
            'maxCount' => 3, // default -1, means no rescriction
        ]
    ],
    'ignore' => [
        'b',
        'h1',
        'h2',
        'a',
        '.ignored',
        '#ad',
    ]
]);
$htmlChanger->replace(function ($text, $value) {
    return $text . '/' . $value;
});

// print html code
print $htmlChanger->html();