PHP Classes

PHP Strip Tags from Strings: Strip tags from a HTML string in several ways

Recommend this page to a friend!
  Info   View files Documentation   View files View files (2)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 135 This week: 1All time: 9,272 This week: 560Up
Version License PHP version Categories
strip-tags-php 1.0.0The PHP License7.2HTML, PHP 5, Parsers
Description 

Author

This class can strip tags from a HTML string in several ways.

It can take a string to find HTML tags with given names and removes them according to certain criterion. Currently the class can:

- Remove all the tags in string
- Remove just specific tags and all contained HTML elements or data
- Remove all tags except a given list of tags
- Remove all tags except given tags with given attributes

Picture of Matheusz Maydana
  Performance   Level  
Name: Matheusz Maydana <contact>
Classes: 2 packages by
Country: Brazil Brazil
Age: 28
All time rank: 4265348 in Brazil Brazil
Week rank: 4 Up1 in Brazil Brazil Up

Documentation

Remover Tags/script HTML em PHP

PT-BR

  • Modo de uso SIMPLES;

// texto exemplo <br/> $string = '\<p id="paragrafo1" class="paragrafo">O importante é oque mais importa! \<br /> No final tudo é 0 e 1.\</p>';

// Instancia a classe $strip = new StripTags;

// coloca a $string na função para remover as tags

$nova_string = $strip->strip_tags($string);

-- A saída vai ser <br /> O importante é oque mais importa! No final tudo é 0 e 1.

para permitir tags, vamos permitir o \<p>

$nova_string = $strip->strip_tags($string, 'p');

-- A saída vai ser <br /> \<p>O importante é oque mais importa! No final tudo é 0 e 1.\</p>

// O segundo parâmetro pode ser string ou array usage.. <br /> $tags_permitidas = array('div', 'a', 'p');

$nova_string = $strip->strip_tags($string, $tags_permitidas);

para permitir atributos, vamos permitir o atributo class

$nova_string = $strip->strip_tags($string, 'p', 'class');

-- A saída vai ser <br /> \<p class="paragrafo1">O importante é oque mais importa! No final tudo é 0 e 1.\</p>

// O terceiro parâmetro pode ser string ou array usage.. <br /> $tags_permitidas = array('div', 'a', 'p'); <br /> $atributos_permitidos = array('class', 'id', 'data-nome');

$nova_string = $strip->strip_tags($string, $tags_permitidas, $atributos_permitidos);

PT-EN

-- mode usage simple

// string exemple <br /> $string = '\<p id="paragrafo1" class="paragrafo">The important is what matters most \<br /> Not everything is 0 and 1.\</p>';

// Instance the class (invok) <br /> $strip = new StripTags;

// put the string in the function of remove the tags

$new_string = $strip->strip_tags($string);

-- output will be <br /> The important is what matters most Not everything is 0 and 1.

To allowed tags, let's allowed the \<p>

$new_string = $strip->strip_tags($string, 'p');

-- output will be <br /> \<p>The important is what matters most Not everything is 0 and 1.\</p>

// the second parameter can be string or array, usage <br /> $tags_allowed = array('div', 'a', 'p');

$new_string = $strip->strip_tags($string, $tags_allowed);

To allowed attributes, let's allowed the attribute class

$new_string = $strip->strip_tags($string, 'p', 'class');

-- output will be <br /> \<p class="paragrafo1">The important is what matters most Not everything is 0 and 1.\</p>

// the third parameter can be string or array, usage <br /> $tags_allowed = array('div', 'a', 'p'); <br /> $attributes_allowed = array('class', 'id', 'data-name');

$new_string = $strip->strip_tags($string, $tags_allowed, $attributes_allowed);

-- ass: Matheus Maydana'


  Files folder image Files  
File Role Description
Accessible without login Plain text file README.md Doc. Documentation
Plain text file Striptags.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:135
This week:1
All time:9,272
This week:560Up