Jump to content

[SOLVED] Truncating at quotes


blkraven

Recommended Posts

As many others I am new to this and am having a problem displaying data returned from a database table.

 

The data contains a quote mark which I am pretty certain is my problem.

 

The data returned is a product description such as - 14" bowl.

 

When I display the field most of the time it displays ok.  such as:

 

<td><span class="style2"><?php echo "{$row['DESCRIPTION']}"; ?></span></td>

 

Returns: 14" Bowl

 

But when I try the following:

 

<td colspan = "5"><input type="text" name="DESCRIPTION" value="<?php echo "{$row['DESCRIPTION']}"; ?>"id="DESCRIPTION" size="100"  /></td>

 

All I get returned is 14

 

It cuts it off at the quote.

 

Can someone help with what I am doing wrong.

Link to comment
https://forums.phpfreaks.com/topic/140586-solved-truncating-at-quotes/
Share on other sites

An echo replaces a statement with whatever it returns... thus:

 

<td colspan = "5"><input type="text" name="DESCRIPTION" value="<?php echo "{$row['DESCRIPTION']}"; ?>"id="DESCRIPTION" size="100"  /></td>

 

Will return:

 

<td colspan = "5"><input type="text" name="DESCRIPTION" value="14""id="DESCRIPTION" size="100"  /></td>

 

Not terribly correct HTML.

 

You should use encoded characters, see http://uk.php.net/html_entities.

 

For example:

 

$strDesc = html_entities($row['DESCRIPTION'], ENT_QUOTES);

 

The ENT_QUOTES is important, otherwise quotes won't be converted :)

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.