Jump to content

[SOLVED] How the echo "


garethhall

Recommended Posts

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.