PHP clears all useless tags in a string _php tips

Source: Internet
Author: User

This example describes the way in which PHP clears all the unwanted tags in a string. Share to everyone for your reference. The implementation methods are as follows:

Many times you need to output some "pure" strings, that is, remove any impurities, such as Html tags, spaces and other text, the output of the summary is so, the following function can help you achieve a bit.

The PHP instance code is as follows:

Copy 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;
}

Use the following methods:
Copy Code code as follows:
echo bing_string_cleanr (' content <br>

PHP Delete blank, the code is as follows:

Copy Code code as follows:
<?php
$STR = "This line containstliberal RN with Whitespace.nn";

The leading/trailing whitespace
Remove the start and end blanks
$str = Trim ($STR);

Now remove any doubled-up whitespace
To take the rest of the space and squeeze it in.
$str = Preg_replace ('/s (? =s)/', ', $str);

Finally, replace any non-space whitespace and a space
Finally, remove the blank space, using a space instead
$str = preg_replace ('/[nrt]/', ', ', $str);
Echo out: ' This line contains liberal the use of whitespace. '
echo "<pre>{$str}</pre>";
?>

I hope this article will help you with your PHP program design.

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.