Simple introduction to Htmlspecialchars, Strip_tags and addslashes functions in PHP

Source: Internet
Author: User
Tags function examples
Htmlspecialchars, Strip_tags, addslashes functions are the most common in the development of web-based programs, and this article will introduce these three functions separately.

1.strip_tags () function

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

Example

<?php$name= "Hello <b>world!</b>"; $tags =strip_tags ($name); Echo $tags;                        >

2.htmlspecialchars () function

The Htmlspecialchars () function converts pre-defined characters to HTML entities.

Specifically, this function translates the following characters:

    • & (and) turn into &

    • "(double quotation marks) to turn"

    • < (less than) turn into <

    • > (greater than) turn into >

Example

<?php$str = "This is some <b>bold</b> text."; echo Htmlspecialchars ($STR);? >

3.htmlentities () function

Perhaps you are still sorry htmlspecialchars can only handle 4 HTML tags, so now you do not regret, htmlentities is to convert all characters. Not very powerful.

Example

<?php$str = "<?" Php?h???? > Echo htmlentities ($str);? >

4. Function stripslashes and addslashes are a pair, addslashes is to use a backslash reference string, Stripslashes is a string that restores addslashes references.

This function is generally a necessary step before a database query, which is preceded by a backslash in order for the database query statement to be preceded by some characters. These characters are single quotes ('), double quotation marks ("), backslashes (/), and NUL (the NULL character).

"Related articles recommended"

PHP Removal string tag strip_tags () Function Example detailed

PHP addslashes () function and stripslashes () function examples

The difference between PHP htmlspecialchars () and Strip_tags functions

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.