PHP to remove HTML tags in the original function of the detailed _php tips

Source: Internet
Author: User
Tags html tags string format types of functions

Strip_tags get rid of HTML and PHP tags. Syntax: string strip_tags (String str); Return value: String function type: Data processing content Description This function can remove any HTML and PHP tag strings contained in the string. If the HTML of the string and PHP tags are original error, such as less than the symbol is greater than, it will return the wrong

Strip_tags

Get rid of HTML and PHP tags.

Syntax: string strip_tags (String str);

return value: String

Types of functions: Data processing

Content Description

This function can remove any HTML and PHP tag strings contained in the string. If the HTML and PHP tags of the string are wrong, such as less than the symbol greater than, it will return the error. This function and FGETSS () have the same functionality.

Htmlspecialchars

Converts a special character into HTML format.

Syntax: String htmlspecialchars (String string);

return value: String

Types of functions: Data processing

This function converts a special character into an HTML string format (&....;). The most commonly used occasions may be to deal with the message version of the customer message.

& (and) Convert to &
"(double quotes) into"
< (less than) turn into <
> (greater than) convert to >
This function converts only the special characters above, and does not convert all to the ASCII conversion specified by HTML.

usage Examples

Copy Code code as follows:

<?php
$new = Htmlspecialchars ("<a href= ' test ' >Test</a>", ent_quotes);
Echo $new;
?>

Attached is an application example in my project:

In the database when the MySQL database will escape the special symbols, then we will be escaped when reading, and my project needs to n_info the contents of the field first remove HTML tags, and then intercept 60 characters of the content displayed

This thought that the direct use of strip_tags () can be achieved, the actual use of the time to find because the contents of the database is escaped, strip_tags is not recognized, so you need to first special words escape back,

Specific code: _SUBSTR (Strip_tags (Htmlspecialchars_decode ($value [' n_info ']), 0, 60)

Related Article

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.