导航首页 » 技术教程 » PHP字符串函数stripslashes()的用法
PHP字符串函数stripslashes()的用法 131 2023-12-12   

stripslashes

(PHP 4, PHP 5)

stripslashes — 反引用一个引用字符串

说明

string stripslashes ( string $str )

反引用一个引用字符串。

Note:

如果 magic_quotes_sybase 项开启,反斜线将被去除,但是两个反斜线将会被替换成一个。

一个使用范例是使用 PHP 检测 magic_quotes_gpc 配置项的 开启情况(在 PHP 5.4之 前默认是开启的)并且你不需要将数据插入到一个需要转义的位置(例如数据库)。例如,你只是简单地将表单数据直接输出。

参数

str

输入字符串。

返回值

返回一个去除转义反斜线后的字符串(' 转换为 ' 等等)。双反斜线(\)被转换为单个反斜线()。

范例

Example #1 stripslashes() 范例

<?php
$str = "Is your name O'reilly?";

// 输出: Is your name O'reilly?
echo stripslashes($str);
?>

Note:

stripslashes() 是非递归的。如果你想要在多维数组中使用该函数,你需要使用递归函数。

Example #2 对数组使用 stripslashes()

<?php
function stripslashes_deep($value)
{
    $value = is_array($value) ?
                array_map('stripslashes_deep', $value) :
                stripslashes($value);

    return $value;
}

// 范例
$array = array("f\'oo", "b\'ar", array("fo\'o", "b\'ar"));
$array = stripslashes_deep($array);

// 输出
print_r($array);
?>

以上例程会输出:

Array
(
    [0] => f'oo
    [1] => b'ar
    [2] => Array
        (
            [0] => fo'o
            [1] => b'ar
        )
)

参见

addslashes() - 使用反斜线引用字符串 get_magic_quotes_gpc() - 获取当前 magic_quotes_gpc 的配置选项设置


!!!站长长期在线接!!!

网站、小程序:定制开发/二次开发/仿制开发等

各种疑难杂症解决/定制接口/定制采集等

站长微信:lxwl520520

站长QQ:1737366103