wordpress 函数:stripslashes-云顶国际

使用 stripslashes 函数去掉 /,如果输入的是对象,使用 get_object_vars 转换成数组,然后对数组递归调用 stripslashes_deep,去掉数组中每个值的 / 。

用法

参数

$value
(array|string) (required) 将要去掉 / 的数组或者字符串。
default: none

返回值

(array|string) 
去掉 / 的数组或者字符串。

实例

基本例子:

$_post = stripslashes_deep( $_post );

最佳实践:

if ( get_magic_quotes_gpc() ) {
    $_post      = array_map( 'stripslashes_deep', $_post );
    $_get       = array_map( 'stripslashes_deep', $_get );
    $_cookie    = array_map( 'stripslashes_deep', $_cookie );
    $_request   = array_map( 'stripslashes_deep', $_request );
}

注解

  • 默认忽略 php 设置的 magic quotes 的值(magic_quotes_gpc 为 true 时,自动给 ' " \ 添加 /),都会给字符串加上 magic quotes。(甚至 php 5.4 删除这个功能)
  • 这样做的原因是太多 核心和插件代码依赖这个功能,所以禁用 magic quotes 会引起一些安全漏洞。

修改记录

since: 2.0.0

源文件

wp-includes/formatting.php

         
网站地图