PHP methods to clear all useless tags in strings

Source: Internet
Author: User
This article mainly introduces how PHP clears all useless tags in strings, and involves clearing spaces and html tags in strings. It is a very practical technique. For more information, see.

This article mainly introduces how PHP clears all useless tags in strings, and involves clearing spaces and html tags in strings. It is a very practical technique. For more information, see.

This example describes how to clear all useless tags in a string in PHP. Share it with you for your reference. The specific implementation method is as follows:

Many times, you need to output some "pure" strings, that is, to remove any impurities, such as Html tags, spaces, and other text. This is the output abstract, the following function can help you implement one point.

The PHP instance code is as follows:

The Code is 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;
}


The usage is as follows:

The Code is as follows:

Echo Bing_string_cleanr ('internal capacity
Asdfeiuonsdfje ');

Php deletes the blank space. The Code is as follows:

The Code is as follows:

<? Php
$ Str = "This line containstliberal rn use of whitespace. nn ";

// First remove the leading/trailing whitespace
// Remove the start and end spaces.
$ Str = trim ($ str );

// Now remove any doubled-up whitespace
// Remove the blank space crowded with other items
$ Str = preg_replace ('/s (? = S)/', '', $ str );

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

{$str}
";
?>

I hope this article will help you with PHP programming.

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.