stripcslashes

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

stripcslashesaddcslashes() でクォートされた文字列をアンクォートする

説明

stripcslashes(string $string): string

バックスラッシュを取り除いた文字列を返します。C言語と同様に \n, \r ..., 8進表現, 16進表現を認識します。

パラメータ

string

元に戻したい文字列。

戻り値

元に戻した文字列を返します。

例1 stripcslashes() の例

<?php

var_dump
(stripcslashes('I\'d have a coffee.\nNot a problem.') === "I'd have a coffee.
Not a problem."
); // true
?>

参考

  • addcslashes() - C 言語と同様にスラッシュで文字列をクォートする

add a note add a note

User Contributed Notes 2 notes

up
11
rafayhingoro[at]hotmail[dot]com
7 years ago
stripcslashes does not simply skip the C-style escape sequences \a, \b, \f, \n, \r, \t and \v, but converts them to their actual meaning.

So
<?php
stripcslashes
('\n') == "\n"; //true;

$str = "we are escaping \r\n"; //we are escaping

?>
up
-34
jsmneo at dreamworkstudio dot net
16 years ago
you might want to do a double stripslashes to completely remove 3 consecutive slashes

$stripped = 'this is a string with three\\\ slashes';
$stripped = stripslahses($stripped);
would output:
'this is a string with three\ slashes'

$stripped = 'this is a string with three\\\ slashes';
$stripped = stripslahses(stripslashes($stripped));
would output:
'this is a string with three slashes'
To Top