angelopc Posted July 23, 2007 Share Posted July 23, 2007 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. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 23, 2007 Share Posted July 23, 2007 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. Quote Link to comment Share on other sites More sharing options...
lur Posted July 23, 2007 Share Posted July 23, 2007 <input type="text" value="<?php echo htmlentities($string_in_database, ENT_QUOTES); ?>" /> Quote Link to comment Share on other sites More sharing options...
angelopc Posted July 23, 2007 Author Share Posted July 23, 2007 Thank you!! I know enough about PHP to know that there is a TON that I don't know. Thanks again. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.