Click to See Complete Forum and Search --> : Help with quotations and PHP writing HTML


damon2003
01-13-2004, 03:14 PM
Hi,
I have a variable that contains info about a product - its code, description and price. For various reasons I have to store this info as a concatenated value, each part separated by ---, and put it in a checkbox

1111---DESCRIPTION OF PRODUCT---36.00

I can echo this ok to a page, but if there happens to be a double quotation mark in the description, then storing this value in the checkbox becomes a problem.
For example if the if the value is the following:

1111---21" TV---36.00

then the value stored in the checkbox becomes:

1111---21

its as though the quotation is being taken literally, and ending the value. This is what I used to write the checkbox to the page

echo "<input type=\"checkbox\" name=\"checkbox$varincrement\" value=\"$productInformation\" checked=\"checked\">";

where $productInformation is the concatenated value above. Does anyone one know how to solve this?
thanks a lot

pyro
01-13-2004, 03:36 PM
Try addslashes() (http://us2.php.net/manual/en/function.addslashes.php).

damon2003
01-15-2004, 10:21 AM
Hi,
I not sure if I am doing this right, I have tried the following:

$new=addslashes($productInformationA);

echo "<input type=\"text\" name=\"checkbox$varincrement\" value=\"$new\" checked=\"checked\">";

and now I get
1437---32\
as the value of the checkbox, before I got
1437---32

it should be
1437---32" WIDESCREEN TV SILVER---549.90
I do get this if I simply echo the value,
how can this be fixed,
thanks

damon2003
01-15-2004, 10:26 AM
I have just tried
htmlspecialchars()
and it works