Jump to content


Photo

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


  • Please log in to reply
9 replies to this topic

#1 SharkBait

SharkBait
  • Members
  • PipPipPip
  • Advanced Member
  • 845 posts
  • LocationMetro Vancouver, BC

Posted 05 September 2006 - 07:08 PM

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:

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

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

Thanks

#2 Stevis2002

Stevis2002
  • Members
  • PipPipPip
  • Advanced Member
  • 98 posts

Posted 05 September 2006 - 07:09 PM

Try putting a / before the "crikey, and a / after the closing quotes

#3 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 05 September 2006 - 07:20 PM

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
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#4 SharkBait

SharkBait
  • Members
  • PipPipPip
  • Advanced Member
  • 845 posts
  • LocationMetro Vancouver, BC

Posted 05 September 2006 - 07:23 PM

I've tried that and in the input box it only displayed a / with no text.

Looking at the source it looks like

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


#5 AdRock

AdRock
  • Members
  • PipPipPip
  • Advanced Member
  • 911 posts

Posted 05 September 2006 - 08:18 PM

I'm sure you should use \ instead of /
If your topic has been solved, please mark the topic as SOLVED.

This helps others from identifying which topics need help still

#6 SharkBait

SharkBait
  • Members
  • PipPipPip
  • Advanced Member
  • 845 posts
  • LocationMetro Vancouver, BC

Posted 05 September 2006 - 10:53 PM

I get this:


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


And it displays only a \ in the text box.

#7 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 06 September 2006 - 01:33 PM

I get this:


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


And it displays only a \ in the text box.


did you try what i suggested above?
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#8 SharkBait

SharkBait
  • Members
  • PipPipPip
  • Advanced Member
  • 845 posts
  • LocationMetro Vancouver, BC

Posted 06 September 2006 - 03:07 PM

Sorry Obsidian, didnt see your reply. I will use that. I knew there was a function for the entities but couldn't remember it.

#9 AdRock

AdRock
  • Members
  • PipPipPip
  • Advanced Member
  • 911 posts

Posted 06 September 2006 - 07:15 PM

Have you tried using 2 single quotes like here ''
It looks like "

might work !!
If your topic has been solved, please mark the topic as SOLVED.

This helps others from identifying which topics need help still

#10 SharkBait

SharkBait
  • Members
  • PipPipPip
  • Advanced Member
  • 845 posts
  • LocationMetro Vancouver, BC

Posted 07 September 2006 - 02:30 AM

I did what bbsidian suggested and it worked.  I was using double quotes and they are now working properly thanks to
htmlentities($blah);





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users