I have a string in my code as per the following example:
\'; ?>
Use htmlspecialchars()
echo htmlspecialchars('string you want to echo');