@scotty_walker use addslashes() function to escape quotes in PHP, code:
1 2 3 4 5 6 |
<?php $str = "How to 'escape quotes' in PHP?"; // Output: How to \'escape quotes\' in PHP? echo addslashes($str); |
@scotty_walker
In PHP, you can escape single quotes ('), double quotes ("), and backslashes () by using a backslash () before the character.
Here are some examples:
By using the backslash () before the character, PHP treats it as a literal character instead of special characters.