addslashes and addcslahes
Posted
by theband
on Stack Overflow
See other posts from Stack Overflow
or by theband
Published on 2010-05-08T23:09:26Z
Indexed on
2010/05/08
23:18 UTC
Read the original article
Hit count: 187
php
I was seeing today the addslashes and addcslashes in php.net, but did not get the point on what is the difference between them and what are the characters escaped in these two.
<?php
$originaltext = 'This text does NOT contain \\n a new-line!';
$encoded = addcslashes($originaltext, '\\');
$decoded = stripcslashes($encoded);
//$decoded now contains a copy of $originaltext with perfect integrity
echo $decoded; //Display the sentence with it's literal \n intact
?>
If i comment the $decoded variable and echo $encoded, i get the same value which is in the original string.
Can anyone clearly explain me the difference and use of these two.
© Stack Overflow or respective owner