You should use htmlspecialchars. It replaces characters as below:
- '&' (ampersand) becomes
&
- '"' (double quote) becomes
"
when ENT_NOQUOTES is not set.
- "'" (single quote) becomes
'
only when ENT_QUOTES is set.
- '<' (less than) becomes
<
- '>' (greater than) becomes
>