PHP clears all useless tags in a string by PHP string _php Tutorial

Source: Internet
Author: User

PHP clears all useless tags in the string, PHP string


This example describes how PHP cleans up all the useless tags in a string. Share to everyone for your reference. The implementation method is as follows:

Many times need to output some "pure" string, that is, to remove any impurities, such as Html tags, spaces, such as text, the output of the digest is so, the following function can help you achieve a point.

The PHP instance code is as follows:
Copy the Code code as follows: function Bing_string_cleanr ($string) {
$string = Trim ($string);
$string = Strip_tags ($string);
$string = Htmlspecialchars ($string, ent_quotes, ' UTF-8 ');
$string = Str_replace ("n", "", $string);
$string = Trim ($string);
return $string;
}
Here's how to use it:
Copy the Code code as follows: Echo Bing_string_cleanr (' content
Asdfeiuonsdfje ');

PHP Delete blank, the code is as follows:
Copy the Code code as follows: <?php
$STR = "This line containstliberal RN use of whitespace.nn";

First remove the leading/trailing whitespace
Remove the opening and closing blanks
$str = Trim ($STR);

Now remove any doubled-up whitespace
Remove the blank that follows the other squeeze
$str = Preg_replace ('/s (? =s)/', ' ', $str);

Finally, replace any non-space whitespace, with a space
Finally, remove the non-space space, with a space instead
$str = preg_replace ('/[nrt]/', ' ', $str);
Echo out: ' This line contains liberal use of whitespace. '
echo "

{$STR}
";
?>

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/920624.html www.bkjia.com true http://www.bkjia.com/PHPjc/920624.html techarticle PHP clears all the useless tags in the string, the PHP string example describes how PHP clears all the useless tags in the string. Share to everyone for your reference. Concrete implementation of the party ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.