Re: Display strings with single quotes
| From: | Ernest E Vogelsinger | Date: | Thu, 20 Feb 2003 12:26:17 +0000 |
| Subject: | Re: Display strings with single quotes | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-136341@lists.php.net to get a copy of this message | ||
At 13:16 20.02.2003, Tom Rogers said:
--------------------[snip]--------------------
>Rec> Have simple but annoying issue, I want to display a string
>within an
>Rec> input field. This string contains ' & so when it's being display the,
>Rec> anything after the ' is being left out. Here is the code I'm using:
>
>Rec> $string = str_replace("'", "''", $string);
>Rec> $string = stripslashes($string);
>Rec> echo "<input type=text name='value' size=20 value =
>Rec> '$string'>";
>
>
>Pass the string through htmlentities(); before you echo it.
--------------------[snip]--------------------
htmlentities won't work with single quotes, use addslashes:
"<input type='text' name='value' size='20'
value='" .
htmlentities(addslashes($string)) . "'>";
--
>O Ernest E. Vogelsinger
(\) ICQ #13394035
^ http://www.vogelsinger.at/