Php native functions for removing html tags

Source: Internet
Author: User
This article mainly introduces the native function of php to remove html tags. for details, refer to strip_tags to remove HTML and PHP tags. Syntax: string strip_tags (string str); return value: string function type: data processing content description this function removes any HTML and PHP Mark strings contained in the string. If the HTML and PHP tags of a string are incorrect, for example, if a greater symbol is missing, an error is returned.

Strip_tags

Remove HTML and PHP tags.

Syntax: string strip_tags (string str );

Return value: string

Correspondence type: data processing

Description

This function removes any HTML and PHP tag strings contained in the string. If the HTML and PHP tags of a string are incorrect, for example, if a greater symbol is missing, an error is returned. This function has the same function as fgetss.

Htmlspecialchars

Convert special characters to HTML format.

Syntax: string htmlspecialchars (string );

Return value: string

Correspondence type: data processing

This function converts special characters into the string format of HTML (&....;). The most common use case may be the message board for handling customer messages.

& (And) &
"(Double quotation marks)"
<(Less than) to <
> (Greater than) to>
This function only converts the preceding special characters and does not convert all the characters to the ASCII conversion specified in HTML.

Example

The code is as follows:


<? Php
$ New = htmlspecialchars ("Test", ENT_QUOTES );
Echo $ new;
?>

Attach an application instance in your project:

When saving the data to the database, the mysql database will escape the special characters, which will be escaped when we read the data. in my project, we need to remove the HTML tag from the content in the n_info field first, then, the 60-character content is captured and displayed.

This is intended to be used directly.Strip_tags ()It can be achieved. in actual use, it is found that the content in the database is escaped and strip_tags cannot be identified. Therefore, special characters need to be escaped first,

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.