Home >Backend Development >PHP Tutorial >Analysis of related PHP functions for escaping HTML and filtering links in WordPress

Analysis of related PHP functions for escaping HTML and filtering links in WordPress

WBOY
WBOYOriginal
2016-07-29 09:09:40991browse

esc_html() (Escape Html) The
esc_html() function is used to escape Html code so that the Html code is not escaped.

Usage

esc_html( $text );

Parameters

$text

(String) (required) The string to escape.

Default value: None

Return value

(String) Returns the escaped characters.

Example

echo esc_html( '<a href="http://www.example.com/">A link</a>' );

The above code will output:

WordPress function: esc_html() (escape Html)

(To prevent the browser from transcoding, I directly screenshot a picture)

More

This function is located at: wp-includes/formatting.php


esc_url() (filter link)
Many URLs will have some minor errors. Use the esc_url() function to block or correct these errors, and reject unsafe protocols. .

What the esc_url() function does:

Reject URLs that are not the following protocols by default: defaulting to http, https, ftp, ftps, mailto, news, irc, gopher, nntp, feed and telnet
Remove invalid characters and dangerous ones Character
Convert characters into HTML entity characters
Usage

esc_url( $url, $protocols, $_context );

Parameters

$url

(string) (required) The URL to be filtered.

Default value: None

$protocols

( Array) (optional) An array of protocols that can be received. If not set, the default is: defaulting to http, https, ftp, ftps, mailto, news, irc, gopher, nntp, feed and telnet.

Default: None

$_context

(String) (optional) How to return the URL.

Default value: (String) display

Return value

(String) Returns the filtered link.

Example

<&#63;php echo esc_url( 'www.endskin.com' );//输出:http://www.endskin.com &#63;>

More

This function is located at: wp-includes/formatting.php

The above introduces the analysis of the use of PHP functions related to escaping HTML and filtering links in WordPress, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn