garethhall Posted September 23, 2009 Share Posted September 23, 2009 Hello I am on an update page but I cant seem to get the data in the text field. So say we have the following code how could I get the value populated when the text contains " and '. Say I have a book $title = 'The "Big" cat's' Is there a addslases function I can use? <input type="text" name="book" value="<?php echo $title?>" /> // this don't work <input type="text" name="book" value='<?php echo $title?>' /> // this to don't work Quote Link to comment Share on other sites More sharing options...
nuttycoder Posted September 23, 2009 Share Posted September 23, 2009 try <input type="text" name="book" value="<?php echo $title; ?>" /> it was missing the ; Quote Link to comment Share on other sites More sharing options...
thebadbad Posted September 23, 2009 Share Posted September 23, 2009 try <input type="text" name="book" value="<?php echo $title; ?>" /> it was missing the ; The semi-colon is not required when the PHP closing tag appears on the same line. But I would use it anyway. @OP You want to use htmlentities(): <input type="text" name="book" value="<?php echo htmlentities($title); ?>" /> Can't remember if you need to run html_entity_decode() on the value later though. Quote Link to comment Share on other sites More sharing options...
Garethp Posted September 23, 2009 Share Posted September 23, 2009 Um, you'd use $title = 'The "Big" cat\'s'; or $title = "The \"Big\" cat's"; Quote Link to comment Share on other sites More sharing options...
nuttycoder Posted September 23, 2009 Share Posted September 23, 2009 try <input type="text" name="book" value="<?php echo $title; ?>" /> it was missing the ; The semi-colon is not required when the PHP closing tag appears on the same line. But I would use it anyway. I din't know that learn something new everyday still woulden't do it that way, same as I never use <?=$title;?> Quote Link to comment Share on other sites More sharing options...
thebadbad Posted September 23, 2009 Share Posted September 23, 2009 try <input type="text" name="book" value="<?php echo $title; ?>" /> it was missing the ; The semi-colon is not required when the PHP closing tag appears on the same line. But I would use it anyway. I din't know that learn something new everyday still woulden't do it that way, same as I never use <?=$title;?> Same here. Good on ya. @Garethp You misunderstood the OP. Your code would still mess up the HTML. 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.