Forum : How do I escape a string with slashes?
Brief description  about Online courses   join in Online courses
View Abhijit  Paul 's Profile

How do I escape a string with slashes?

How do I escape a string with slashes???????
Asked by Abhijit Paul | Mar 17, 2010 |  Reply now
Replies (1)
View teacher siliconindia 's Profile
Hi Abhijit,
This is really easy to do, and simply relies on you using the addslashes function like this:

<?php
$contents = "I'm very happy today";
echo addslashes($contents);
//I\'m very happy today
?>

That's all there is to it, simply done. Remember that if you want to take those slashes off, for instance once data has been extracted from a database, you can use the opposite function called stripslashes to remove them.
Mar 17, 2010