Jump to content

[SOLVED] Questions about problems with quotes and echos


Chappers

Recommended Posts

Hi,

 

Having some problems regarding quotes. I'm taking an entry from the MySQL table in the format 5'11" (as in five feet eleven inches). This is my variable $height.

 

$height = $row['height'];

 

Then I place it in a form which can be edited, which is inside an echo container:

 

echo "
<td><span class=\"n\">Height:</span></td>
<td><input class=\"n2\" type=\"text\" name=\"height\" maxlength=\"100\" value=\"$height\"></td>
";

 

Which displays the height without the quote mark for inches, i.e. 5'11

 

So I thought I'd try a replace:

 

$height = $row['height'];
$height2 = str_replace('"','\"',$height);

 

But that just outputs: 5'11\

 

What's the usual way around this, considering that the height variable contains both single and double quote marks?

 

I know one can use echo ?> then the HTML and add variables with <?php echo $height ?> so double quotes are still usable, but since the elements use quotes as delimiters, like value="height", how can another double quote be added in there without it thinking it's the delimiter. There must be a way around this? I found one webpage that stated putting two single quotes will output just one when entering the information into a MySQL database, but that's as far as I got with help on the net.

 

Thank you to any and all who take this question on.

 

James

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.