Home  >  Article  >  Backend Development  >  Analysis of related PHP functions for escaping HTML and filtering links in WordPress, _PHP tutorial

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

WBOY
WBOYOriginal
2016-07-12 09:02:37793browse

The related PHP functions for escaping HTML and filtering links in WordPress use parsing,

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 be escaped.

Default value: None

Return value

(String) Returns the escaped character.

Example

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

The above code will output:

WordPress function: esc_html() (escape Html)

(In order to prevent the browser from transcoding, I directly took a screenshot)

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:

Defaulting to URLs that are not the following protocols: defaulting to http, https, ftp, ftps, mailto, news, irc, gopher, nntp, feed and telnet
Remove invalid and dangerous characters
Convert characters to HTML entity characters
How to use

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

Parameters

$url

(String) (required) 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 value: None

$_context

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

Default: (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

Articles you may be interested in:

  • Detailed explanation of the methods of filtering links and filtering SQL statements in WordPress
  • Detailed explanation of the use of filter attributes and functions of Sql statements in WordPress development

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1084560.htmlTechArticleUsage analysis of PHP functions related to escaping HTML and filtering links in WordPress, esc_html() (escape Html) esc_html( ) function is used to escape Html code so that Html code is not escaped. Usage es...
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