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 Link to comment https://forums.phpfreaks.com/topic/175282-solved-how-the-echo/ 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 ; Link to comment https://forums.phpfreaks.com/topic/175282-solved-how-the-echo/#findComment-923814 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. Link to comment https://forums.phpfreaks.com/topic/175282-solved-how-the-echo/#findComment-923818 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"; Link to comment https://forums.phpfreaks.com/topic/175282-solved-how-the-echo/#findComment-923820 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;?> Link to comment https://forums.phpfreaks.com/topic/175282-solved-how-the-echo/#findComment-923821 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. Link to comment https://forums.phpfreaks.com/topic/175282-solved-how-the-echo/#findComment-923823 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.