friedolinfoerder / html-changer
解析HTML并更改输出
v0.1.6
2021-10-10 19:05 UTC
Requires
- php: >=5.5.0
Requires (Dev)
- kahlan/kahlan: ^4.5
README
使用这个小巧的库,您可以解析HTML代码并更改输出。与其他许多类似模块不同,此库在解析时不会更改现有代码。因此,您可以仅更改需要更改的部分,而保留所有其他代码不变。
安装
composer require friedolinfoerder/html-changer
用法
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();