Jump to content

Archived

This topic is now archived and is closed to further replies.

SharkBait

Hard to replace " (double quote) in a string for form

Recommended Posts

Hi,

I'm having troubles with inserting values into an HTML form.

This is the value in the databae:  "Crikey", look at the size of that thing!

To be put into:

[code]<input type="text" name="title" value="<?php echo $valueFromDB;">" />[/code]

But because Crikey is enclosed with " " it breaks the HTML.  How do I fix this? Do I just replace all " with ' ?

Thanks

Share this post


Link to post
Share on other sites
if you're placing the text into an HTML tag, you'll most likely need to change it to HTML entities to get it to display properly. for instance, instead of having double quotes, you'll need to use &quot; instead. to easily accomplish this, just run your string through htmlentities() before outputting it to the browser.

good luck

Share this post


Link to post
Share on other sites
I've tried that and in the input box it only displayed a / with no text.

Looking at the source it looks like

[code]<td><input type="text" size="20" name="title" value="/"Crikey/" it's a stingray!" /> Title</td>[/code]

Share this post


Link to post
Share on other sites
I get this:

[code]

<td><input type="text" size="20" name="title" value="\"Crikey\" it's a stingray!" /> Title</td>

[/code]

And it displays only a \ in the text box.

Share this post


Link to post
Share on other sites
[quote author=SharkBait link=topic=106988.msg428832#msg428832 date=1157496795]
I get this:

[code]

<td><input type="text" size="20" name="title" value="\"Crikey\" it's a stingray!" /> Title</td>

[/code]

And it displays only a \ in the text box.
[/quote]

did you try what i suggested above?

Share this post


Link to post
Share on other sites
Sorry Obsidian, didnt see your reply. I will use that. I knew there was a function for the entities but couldn't remember it.

Share this post


Link to post
Share on other sites
Have you tried using 2 single quotes like here ''
It looks like "

might work !!

Share this post


Link to post
Share on other sites
I did what bbsidian suggested and it worked.  I was using double quotes and they are now working properly thanks to [code=php:0]htmlentities($blah);[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.