Data sanitization escaping HTML apostrophes

It should add a slash when storing the data. And then you use stripslashes when you want to display it.

$str = "Is your name O\'Reilly?";

echo stripslashes($str); // Outputs: Is your name O'Reilly?

If a slash is not added, all sorts of unexpected things can happen because the apostrophe can be handled as the opening or closing of a string.

Leave a Comment