(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 的配置選項設置