Jump to content

[SOLVED] Text Returned From DB Gets Cutoff When Placed In A Text Field


angelopc

Recommended Posts

I know this is easy...or at least I hope it is. I tried to find this problem already posted and couldn't, however I'm sure I'm not the first. I have a string that contains an apostrophe or a quotation mark, stored in a DB. I can retrieve the data, and display it properly (for editing) in a textarea, but when I try to put the string in a text field, it get's cut off right before the questionable character.

 

For example:

$string_in_database = "John's car."

 

-displays correctly here <textarea><?php print $string_in_database ?></textarea> and displays this - John's car.

 

-gets cutoff here <input type='text' value=''<?php print $string_in_database ?>' /> and displays this -  John

 

I've tried adding slashes and stripping slashes and I just can't figure out what I need to do. Please let me know if this is unclear to anyone. I appreciate your help.

Link to comment
Share on other sites

You'll ned to enclose the value in a differant type of quote to the one thats in the string. So your example, try:

 

<input type = "text" value="<?php echo $string_in_database; ?>" />

 

Its because when the browser reads the HTML it finds the quote that got echoed by the php and thinks thats the terminating quote.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.