I use this code to genefate html
echo "<input type='button' onclick=\"myFunc('$param');\" />";
Everything would be OK unless $param contains '
or "
character. How should it be implemented to handle these situations?
ps. mysql_real_escape_string($param) won't work correctly, when a user entered "
.
echo "\"$animal\""; Or you can just use single quotes instead as the following: echo '"$animal"'; Whichever you prefer.
'Remember to say "please" and "thank you."'; Alternatively, you can use a backslash \ to escape the quotation marks.
Just escape them: echo "\"$time\""; You could also use single around the double quotes: echo '"' .
There are a couple of functions that could be used:
<?php
$string = 'string test"';
echo htmlentities($string) . "\n";
echo addslashes($string) . "\n";
They produce the following:
string test"
string test\"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With