當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


PHP stripcslashes()用法及代碼示例

stripcslashes() 是 PHP 中的內置函數,用於刪除為轉義字符串中某些字符而添加的反斜杠。它反轉了 addslashes() 函數的效果。它識別 C-language 字符,例如 \n、\r …、八進製和十六進製表示形式。

用法

stripcslashes(string $string): string;

參數

該函數僅接受單個參數,如下所述:

  • $字符串:要從中刪除反斜杠的輸入字符串。

返回值

stripcslashes() 函數從未轉義的字符串返回轉義的字符串。

程序1:下麵的程序演示了stripcslashes()函數。

PHP


<?php 
$escaped_string =  
      "This is an example with \\'escaped\\' characters."; 
$original_string = stripcslashes($escaped_string); 
echo "Escaped String: $escaped_string<br>.\n"; 
echo "Original String: $original_string"; 
?>
輸出
Escaped String: This is an example with \'escaped\' characters.<br>.
Original String: This is an example with 'escaped' characters.

程序2:下麵是另一個程序,演示了stripcslashes()函數。

PHP


<?php 
$escaped_string =  
      "This is an example with \\'escaped\\' characters."; 
$original_string = stripcslashes($escaped_string); 
if ($escaped_string === $original_string) { 
    echo 
    "String was not escaped: $original_string"; 
} else { 
    echo 
    "String was escaped and then unescaped: $original_string"; 
} 
?>
輸出
String was escaped and then unescaped: This is an example with 'escaped' characters.

參考: https://www.php.net/manual/en/function.stripcslashes.php



相關用法


注:本文由純淨天空篩選整理自neeraj3304大神的英文原創作品 PHP stripcslashes() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。