Home  >  Article  >  Backend Development  >  Detailed explanation of how to filter links and filter SQL statements in WordPress, _PHP tutorial

Detailed explanation of how to filter links and filter SQL statements in WordPress, _PHP tutorial

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

Detailed explanation of the methods of filtering links and filtering SQL statements in WordPress,

esc_url() (filtering links)
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


esc_sql() (filter Sql statement)
esc_sql() is used to filter the strings to be added to Sql statements to prevent Sql injection and Sql statements from being interfered with by data and causing exceptions.

Usage

esc_sql( $data );

Parameters

$data

(String) (Required) The string to filter.

Default value: None

Return value

(string) returns the filtered string, which can be added directly to the Sql statement.

Example

$name = esc_sql( $name );
$status = esc_sql( $status );
$wpdb->get_var( "SELECT something FROM table WHERE foo = '$name' and status = '$status'" );

More

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

Articles you may be interested in:

  • Analysis of PHP functions related to escaping HTML and filtering links in WordPress
  • Detailed explanation of the function usage of filtering attributes and Sql statements in WordPress development

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1084602.htmlTechArticleDetailed explanation of the methods of filtering links and filtering SQL statements in WordPress, esc_url() (filtering links) Many URLs will have some Minor errors can be blocked or corrected using the esc_url() function,...
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