How to use addslashes() function to quote a string with slashes, add backslashes before escape characters in PHP

3 Answers

0 votes
$str = "PHP 'php'";

echo addslashes($str);

   
/*
run: 

PHP \'php\' 

*/

 



answered May 15, 2016 by avibootz
0 votes
$str = '"PHP" php "string"';

echo addslashes($str);

   
/*
run: 

\"PHP\" php \"string\" 

*/

 



answered May 15, 2016 by avibootz
0 votes
$str = 'PHP \php\ string \programming\"';

echo addslashes($str);

   
/*
run: 

PHP \\php\\ string \\programming\\\" 

*/

 



answered May 15, 2016 by avibootz

Related questions

4 answers 377 views
1 answer 114 views
1 answer 182 views
1 answer 241 views
...