How do I escape a string with slashes?
<?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.
Comment on this Question and Answer >>>
ASK A QUESTION
More strings PHP Questions
How do I turn a string into an array?How do I convert characters to HTML entities using PHP?
How do I remove trailing whitespace?
Hello, Is it possible to specify a character-encoding in the filter_var function. Thank you for your reply, Jan
How do I fetch the meta tags from a webpage using PHP?
