Last Updated | | Ratings | | Unique User Downloads | | Download Rankings |
2019-08-28 (Less than 1 hour ago) | | Not yet rated by the users | | Total: 144 This week: 23 | | All time: 8,781 This week: 9 |
|
Description | | Author |
This package can process HTML to strip tags, attributes or PHP code.
It can take a string with HTML and parses it to extract its structure.
The package can either replace or remove given HTML or PHP tags, by passing a list of tags or tag attributes to be removed from the HTML document.
It returns another string the processed HTML after the specified tags and attributes are removed or replaced. Innovation Award
June 2019
Number 4 |
Sometimes it is necessary to extract PHP code from script files on which it is embedded in HTML.
This package not only can extract or remove PHP code from HTML, but can also extract or remove HTML code from scripts that mix HTML with PHP.
Manuel Lemos |
| |
|
|
Innovation award
Nominee: 23x
Winner: 2x |
|
Details
Strip-tags
remove PHP and HTML Tags from a string in a custom and efficient way
Requires: PHP 7.0+
Why strip-tags package if PHP have the strip_tags function ?
you could use it if you :
- want to remove tags with some attributes only
- want to remove some attributes from some tags
- want to strip only HTML not PHP or only PHP not HTML
- want to remove completely some tags and from other tags partially remove some of
their attributes
- want to specify tags to remove instead of tags to keep or tags to keep instead of tags to remove.
How to use it
Require the library by issuing this command:
composer require manuwhat/strip-tags
then you can use it this way:
$data=$data='<!doctype html><html><head>'.$x.$y.'</head><!-- a comment --> <body><?php echo here <br>; ?> <h2 onmousedown="alert(\'keke\');">u</h2><p></p><h2>a</h2></body></html>';
//$data can be a source string or a file
$hstrip=new htmlstrip($data,'remove',array(Htmlstrip::getTags(),true));//strip every thing PHP and HTML TAGS
$hstrip=new htmlstrip($data,'remove',array('<php>,<script>',true));//remove PHP and sript tags
$hstrip=new htmlstrip($data,'replace',array('<php>,<script>',true),array('onemouseover','true'));//remove PHP and sript tags and onemouseover attributes
//tags and attributes can be specified as array instead of string
var_export(htmlspecialchars($hstrip->go()));//execute
//finally you can refine your choices...
var_export(htmlspecialchars($hstrip->go(htmlstrip::TAGS)));//act only on tags
var_export(htmlspecialchars($hstrip->go(htmlstrip::ATTRIBUTES)));//act only on attributes
var_export(htmlspecialchars($hstrip->go(htmlstrip::TAGS_AND_ATTRIBUTES)));//act on tags and attributes this is the default behavior
var_export(htmlspecialchars($hstrip->go(htmlstrip::TAGS_WITH_ATTRIBUTES)));//act on tags with some attributes
To run unit tests
composer test
|
Applications that use this package |
|
No pages of applications that use this class were specified.
If you know an application of this package, send a message to the author to add a link here.