It helps to convert all applicable characters to HTML entities.
<?php
htmlentities($str);
// Outputs: A ‘quote’ is < ;b> ;bold< ;/b> ;
echo htmlentities($str, ENT_QUOTES);
// Outputs: A & #039 ;quote& #039 ; is < ;b> ;bold< ;/b> ; (ENT_QUOTES Will convert both double and single quotes.)
?>
?>