Home  >  Article  >  Backend Development  >  详解WordPress中过滤链接与过滤SQL语句的方法,_PHP教程

详解WordPress中过滤链接与过滤SQL语句的方法,_PHP教程

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

详解WordPress中过滤链接与过滤SQL语句的方法,

esc_url()(过滤链接)
很多 URL 会有一些小错误,用 esc_url() 函数可以屏蔽或者修正这些错误,并且可以拒绝不安全的协议。

esc_url() 函数的工作内容:

默认拒绝不是下面协议的 URL:defaulting to http、https、ftp、ftps、mailto、news、irc、gopher、nntp、feed 和 telnet
删除无效字符和危险的字符
将字符转换成 HTML 实体字符
使用方法

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

参数

$url

(字符串)(必须)要被过滤的 URL.

默认值:None

$protocols

(数组)(可选)可以接收协议的数组,如果没有设置,则默认为:defaulting to http、https、ftp、ftps、mailto、news、irc、gopher、nntp、feed 和 telnet.

默认值:None

$_context

(字符串)(可选)如何返回 URL.

默认值:(字符串)display

返回值

(字符串)返回过滤后的链接。

例子

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

更多

此函数位于:wp-includes/formatting.php


esc_sql()(过滤 Sql 语句)
esc_sql() 用来过滤准备添加到 Sql 语句里边的字符串,防止 Sql 注入和 Sql 语句被数据干扰出现异常。

用法

esc_sql( $data );

参数

$data

(字符串)(必须)要过滤的字符串。

默认值:None

返回值

(字符串)返回过滤后的字符串,可以直接添加到 Sql 语句里。

例子

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

更多

此函数位于:wp-includes/formatting.php

您可能感兴趣的文章:

  • WordPress中转义HTML与过滤链接的相关PHP函数使用解析
  • 详解WordPress开发中过滤属性以及Sql语句的函数使用

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1084602.htmlTechArticle详解WordPress中过滤链接与过滤SQL语句的方法, esc_url()(过滤链接) 很多 URL 会有一些小错误,用 esc_url() 函数可以屏蔽或者修正这些错误,...
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