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

Recommend this page to a friend!
  Info   Documentation   View files (2)   Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 125 All time: 9,108 This week: 278
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: 1 package by
Country: Brazil Brazil
Age: 25
All time rank: 4212346 in Brazil Brazil
Week rank: 762 40 in Brazil Brazil

Details

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  
File Role Description
README.md Doc. Documentation
Striptags.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:125
This week:0
All time:9,108
This week:278

For more information send a message to info at phpclasses dot org.