stripslashes

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

stripslashes反引用一個(gè)引用字符串

說(shuō)明

stripslashes(string $str): string

反引用一個(gè)引用字符串。

注意:

如果 magic_quotes_sybase 項(xiàng)開啟,反斜線將被去除,但是兩個(gè)反斜線將會(huì)被替換成一個(gè)。

一個(gè)使用范例是使用 PHP 檢測(cè) magic_quotes_gpc 配置項(xiàng)的 開啟情況(在 PHP 5.4之 前默認(rèn)是開啟的)并且你不需要將數(shù)據(jù)插入到一個(gè)需要轉(zhuǎn)義的位置(例如數(shù)據(jù)庫(kù))。例如,你只是簡(jiǎn)單地將表單數(shù)據(jù)直接輸出。

參數(shù)

str

輸入字符串。

返回值

返回一個(gè)去除轉(zhuǎn)義反斜線后的字符串(\' 轉(zhuǎn)換為 ' 等等)。雙反斜線(\\)被轉(zhuǎn)換為單個(gè)反斜線(\)。

范例

示例 #1 stripslashes() 范例

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

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

注意:

stripslashes() 是非遞歸的。如果你想要在多維數(shù)組中使用該函數(shù),你需要使用遞歸函數(shù)。

示例 #2 對(duì)數(shù)組使用 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
        )

)

參見