PHP Classes

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

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 136 All time: 9,271 This week: 81Up
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: 3 packages by
Country: Brazil Brazil
Age: 29
All time rank: 4199343 in Brazil Brazil
Week rank: 180 Up12 in Brazil Brazil Up
Innovation award
Innovation award
Nominee: 1x

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 (2)  
File Role Description
Accessible without login Plain text file README.md Doc. Documentation
Plain text file Striptags.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:136
This week:0
All time:9,271
This week:81Up