RE: [PHP] quotes
| From: | Ford, Mike [LSS] | Date: | Thu, 26 Jun 2003 10:01:34 +0000 |
| Subject: | RE: [PHP] quotes | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-152945@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Lso . [mailto:lukas__scott@hotmail.com]
> Sent: 25 June 2003 18:32
>
> ok i see why i didnt work but i dont know why.
>
> can anyone tell me why this works:
>
> <input name="testfield" type="text" value="<? echo
> htmlentities($company)
> ?>">
>
> but this doesn't:
>
> echo "<input name='company' type='text' value='".
> htmlentities($company)
> ."'>";
Because by default htmlentities will convert double quotes but not single ones -- if you convert the
second one to use double quotes in the HTML (like the first one), it should work:
echo '<input name="company" type="text" value="',
htmlentities($company), '">';
Or you could use the optional 2nd parameter to htmlentities to make it convert single quotes as well
-- the following is a quote from the manual page at http://www.php.net/htmlentities:
> the optional second quote_style parameter lets you define what will
> be done with 'single' and "double" quotes. It takes on one of three
> constants with the default being ENT_COMPAT:
>
> Constant Name Description
> ENT_COMPAT Will convert double-quotes and leave single-quotes
> alone.
> ENT_QUOTES Will convert both double and single quotes.
> ENT_NOQUOTES Will leave both double and single quotes unconverted.
Cheers!
Mike
---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS, LS6 3QS, United Kingdom
Email: m.ford@lmu.ac.uk
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211