(PHP 4, PHP 5, PHP 7, PHP 8)
stripslashes — 反引用一個引用字符串
$str): string反引用一個引用字符串。
注意:
如果 magic_quotes_sybase 項開啟,反斜線將被去除,但是兩個反斜線將會被替換成一個。
一個使用范例是使用 PHP 檢測 magic_quotes_gpc 配置項的 開啟情況(在 PHP 5.4之 前默認是開啟的)并且你不需要將數據插入到一個需要轉義的位置(例如數據庫)。例如,你只是簡單地將表單數據直接輸出。
str輸入字符串。
返回一個去除轉義反斜線后的字符串(\' 轉換為 ' 等等)。雙反斜線(\\)被轉換為單個反斜線(\)。
示例 #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
)
)