PHP Removal string tag strip_tags () Function Example detailed

Source: Internet
Author: User
Tags learn php
What is the definition and usage of the PHP strip_tags () function?

Many novice friends learn PHP, sometimes encounter some small problems, such as how to remove the string in the label, string garbled problem, in fact, these problems are very simple, the general garbled problem is the character encoding is not set, as long as the character encoding is set, basically will not appear garbled problem, Specific article can refer to this article PHP Chinese garbled Problem solution Summary, then how to remove the string label it? Actually removes the string the label is also very simple, only need to use the string function strip_tags (), can solve, then how to use this function, this article will take you to understand the php strip_ tags () function.

The definition and usage of PHP strip_tags () function

The Strip_tags () function strips HTML, XML, and PHP tags from the string.

Grammar

Strip_tags (String,allow)

Detailed parameters:

The string argument is a character set to be checked and must have

Allow is not a required parameter, it is a specified string in which tags are allowed, and these tags are not deleted. Do not fill in the default remove all labels

PS: Note: This function always strips HTML comments. This cannot be changed by the Allow parameter.

return value

The Strip_tags () function returns the stripped string.

Example One

Use the Strip_tags () function to remove HTML tags from the string, as follows:

<?php$name= "Hello <b>world!</b>"; $tags =strip_tags ($name); Echo $name. " <br/> ";                  echo $tags before removing HTML tags;                         ?> after removing HTML tags

Code Run output Result:

Example Two

Use the Strip_tags () function to remove HTML tags from the string, but allow <b> tags, as shown in the code below

<?php$name= "Hello <b><i>world!</i></b>"; $tags =strip_tags ($name, "<b>"); echo $ Name. " <br/> ";                  echo $tags before removing HTML tags;                         ?> after removing HTML tags

Code Run output Result:

"Related articles recommended"

One detail to note when using the PHP strip_tags () function

Use the PHP strip_tags () function to keep multiple HTML tag instances detailed

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.