(PHP 4, PHP 5, PHP 7, PHP 8)
stripslashes — 反引用一個(gè)引用字符串
$str
): string反引用一個(gè)引用字符串。
注意:
如果 magic_quotes_sybase 項開(kāi)啟,反斜線(xiàn)將被去除,但是兩個(gè)反斜線(xiàn)將會(huì )被替換成一個(gè)。
一個(gè)使用范例是使用 PHP 檢測 magic_quotes_gpc 配置項的 開(kāi)啟
情況(在 PHP 5.4之 前默認是開(kāi)啟的)并且你不需要將數據插入到一個(gè)需要轉義的位置(例如數據庫)。例如,你只是簡(jiǎn)單地將表單數據直接輸出。
str
輸入字符串。
返回一個(gè)去除轉義反斜線(xiàn)后的字符串(\'
轉換為 '
等等)。雙反斜線(xiàn)(\\
)被轉換為單個(gè)反斜線(xiàn)(\
)。
示例 #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);
?>
以上例程會(huì )輸出:
Array ( [0] => f'oo [1] => b'ar [2] => Array ( [0] => fo'o [1] => b'ar ) )