Escaping both single AND double quotes simultaneously?
Posted on 1999-11-15
I am populating a form using PHP to display the current values of the fields for editing. Example code:
print(" <form> <input type=text name='my_field' value='$my_value'> </form> ");
But if $my_value contains a quote, the value gets truncated. I could switch the single and double quotes, but will always have a problem with one or the other.
All I can think of is to run $my_value through a script to replace all occurences of quotation marks with ". This causes a significant performance hit, and I'm wondering if there isn't a faster more efficient solution to this problem.
I've searched previous answers on this site, but couldn't find anything that worked. Someone mentioned "triple quotes"... I'm not familiar with these, but if it means a single followed by double quote (or vice versa) then I've tried it and it doesn't work.
Thanks in advance...