eissaweb/php-html-text-content
Composer 安装命令:
composer require eissaweb/php-html-text-content
包简介
Change HTML text content using PHP.
README 文档
README
With this package you can change textContent of HTML tag.
install using composer
composer require eissaweb/php-html-text-content:0.1
Examples:
#1 Using String as a parameter
<?php require_once 'vendor/autoload.php'; use PHPHtmlTextContent\ReplaceTextContent; $str = '<div>Hello World!!2</div></p>New Line 2</p>'; // ReplaceTextContent::replace($str, $search, $replace, $callback = null); $replaced = ReplaceTextContent::replace($str, '2', ''); echo $replaced; //Hello World!! // New Line
#2 using array of string as a parameter
<?php require_once 'vendor/autoload.php'; use PHPHtmlTextContent\ReplaceTextContent; $str = '<div>Hello World??2</div>'; // ReplaceTextContent::replace($str, $search, $replace, $callback = null); $replaced = ReplaceTextContent::replace($str, ['2', '?'], ['', '!']); echo $replaced; // Hello World!!
#3 passing callback
you can pass callback as 4th parameter to modify the replaced string.
<?php require_once 'vendor/autoload.php'; use PHPHtmlTextContent\ReplaceTextContent; $str = '<div>Hello World??2</div><div class="username"><a href="github.com/eissaweb">Eissaweb??</a></div>'; // ReplaceTextContent::replace($str, $search, $replace, $callback = null); $replaced = ReplaceTextContent::replace($str, ['2', '?'], ['', '!'], function ($replacedStr) { // in this case you can style the replaced text by using inline style or adding html classes to the tag as you want. return '<span>' . $replacedStr . '</span>'; }); echo $replaced; // Hello World!! // Eissaweb!!
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-05-18