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
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 :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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