ibraheem-ghazi / html-stripper
用于解析HTML标签和HTML内联样式的PHP解析器,允许或禁止某些CSS样式(任何值或特定值)
1.0
2018-04-04 06:53 UTC
Requires
- php: >=5.6.0
This package is not auto-updated.
Last update: 2024-09-19 09:34:59 UTC
README
用于解析HTML标签和HTML内联样式的PHP解析器,允许或禁止某些CSS样式(任何值或特定值)
安装
$ composer require ibraheem-ghazi/html-stripper
函数
strip($str, $useStripTags=true, $allowedTags= ['p','span','b','strong','u','ins','i','em','s','del','ul','li','ol','table','thead','tfoot','tbody','tr','th','td','br'])
paramters:
$str // **(string)** the html code for topic or post
$useStripTags // **(bool)** should use strip tags alongside css stripper
$allowedTags // **(array)** if strip tags is used , then which tags are allowed
return clean clone of input string
addStyle($attribute,$value='*',$condition='=')
paramters:
$attribute // **(string)** which css attribute should allow (Ex: width, height, text-align, font-size, direction, ...etc)
$value // **(string)** which value should allow for this css attribute ('*' mean any value is allowed for this attribute)
$condition // **(string)** allowed value should be equal, less than, or greather than specified value
**use these constants for `` $condition `` : **
HTMLStripper::EQUAL
HTMLStripper::LESS_THAN
HTMLStripper::GREATER_THAN
示例
<?php
require 'vendor/autoload.php';
use IbraheemGhazi\HTMLStripper\HTMLStripper;
$str= require 'input_str.php'; //get string from input_str.php and put it in $str variable
$hss= new HTMLStripper();
$hss->addStyle('margin-right','40px',HTMLStripper::LESS_THAN);//39 and less are allowed
$hss->addStyle('text-align','*',HTMLStripper::EQUAL);
$hss->addStyle('height','30px',HTMLStripper::LESS_THAN);
$hss->addStyle('width','5%',HTMLStripper::GREATER_THAN);
// ... etc
// $new_str = $hss->strip($str,true,['strong','em','p']);
$new_str = $hss->strip($str,true,['table','tr','td','th','p','br']);
echo $new_str;