stripslashes

(PHP 4, PHP 5, PHP 7, PHP 8)

stripslashes反引用一个引用字符串

说明

stripslashes(string $string): string

反引用一个引用字符串。

如果不需要将数据插入到一个需要转义的位置(例如数据库)则可以使用 stripslashes()。例如,直接从 HTML 表单输出数据。

参数

string

输入字符串。

返回值

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

范例

示例 #1 stripslashes() 范例

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

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

注意:

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

示例 #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
        )

)

参见

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top