Home > Backend Development > PHP Tutorial > Three solutions to delete html tags in php, three phphtml tags_PHP tutorial

Three solutions to delete html tags in php, three phphtml tags_PHP tutorial

WBOY
Release: 2016-07-12 08:51:19
Original
791 people have browsed it

Three solutions to delete html tags in php, three ways to delete html tags in php

Share three methods to delete HTMl tags in PHP.

Method 1:
Directly take out the mark you want to take out

Three solutions to delete html tags in php, three phphtml tags_PHP tutorial
<?<span>php
</span><span>//</span><span>取出br标记</span>
<span>function</span> strip(<span>$str</span><span>)
{
</span><span>$str</span>=<span>str_replace</span>("<br>","",<span>$str</span><span>);
</span><span>//</span><span>$str=htmlspecialchars($str);</span>
<span>return</span> <span>strip_tags</span>(<span>$str</span><span>);
} </span><span>//</span><span>edit by www.jbxue.com</span>
?>
Copy after login
Three solutions to delete html tags in php, three phphtml tags_PHP tutorial

Method 2.

There is a strip_tags function in PHP that can easily remove HTML tags.
echo strip_tags(“Hello World”); // Remove HTML, XML and PHP tags.
Non-standard HTML codes can also be removed correctly:
echo strip_tags(“”>cftea”); //Output cftea
in PHP You can use the strip_tags function to remove HTML tags, see the following example:

<?<span>php
</span><span>$str</span> = &lsquo;www.<p>jbxue</p>.com'<span>;
echo(htmlspecialchars($str).&rdquo;<br>&rdquo;);
echo(strip_tags($str));
?></span>
Copy after login

Method 3.

strtr() function converts specific characters in a string.
Syntax
strtr(string,from,to)
or
strtr(string,array)
Parameter Description
string1 Required. Specifies the string to be converted.
from Required (unless using an array). Specifies the character to be changed.
to Required (unless using an array). Specifies the character to change to.
array required (unless from and to are used). An array where the keys are the original characters and the values ​​are the target characters.

Example 1:

<?<span>php
</span><span>echo</span> <span>strtr</span>("Hilla Warld","ia","eo"<span>);
</span>?>
Copy after login

Example 2:

<?<span>php
</span><span>$arr</span> = <span>array</span>("Hello" => "Hi", "world" => "earth"<span>);
</span><span>echo</span> <span>strtr</span>("Hello world",<span>$arr</span><span>);
</span>?>
Copy after login

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1131874.htmlTechArticleThree solutions to delete html tags in PHP, three ways to delete HTMl tags in PHP . Method 1: Directly remove the tag you want to remove ? php // Remove the br tag f...
Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template