PHP Classes
elePHPant
Icontem

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

Recommend this page to a friend!

  Author Author  
Name: Matheusz Maydana <contact>
Classes: 1 package by
Country: Brazil Brazil


  Detailed description   Download Download .zip .tar.gz  
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

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'


  Classes of Matheusz Maydana  >  PHP Strip Tags from Strings  >  Download Download .zip .tar.gz  >  Support forum Support forum  >  Blog Blog  >  RSS 1.0 feed RSS 2.0 feed Latest changes  
Name: PHP Strip Tags from Strings
Base name: strip-tags-php
Description: Strip tags from a HTML string in several ways
Version: -
PHP version: 7.2
License: The PHP License
 
  Groups   Applications   Files Files  

  Groups  
Group folder image HTML HTML generation and processing View top rated classes
Group folder image PHP 5 Classes using PHP 5 specific features View top rated classes
Group folder image Parsers Programming language interpreters and format parsers View top rated classes


  Applications that use this package  
No pages of applications that use this class were specified.

Add link image If you know an application of this package, send a message to the author to add a link here.

  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

Download Download all files: strip-tags-php.tar.gz strip-tags-php.zip
NOTICE: if you are using a download manager program like 'GetRight', please Login before trying to download this archive.