/    Sign up×
Community /Pin to ProfileBookmark

Help with quotations and PHP writing HTML

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

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@pyroJan 13.2004 — Try [URL=http://us2.php.net/manual/en/function.addslashes.php]addslashes()[/URL].
Copy linkTweet thisAlerts:
@damon2003authorJan 15.2004 — 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
Copy linkTweet thisAlerts:
@damon2003authorJan 15.2004 — I have just tried

htmlspecialchars()

and it works
×

Success!

Help @damon2003 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...