How can I display html as code and not have it render?

Here is the line Im working with

<td align=“left” class=“<?php echo $cellColor; ?>”><span class=“copyText”>
<?php echo ‘<input type=“text” size=“20” name="d’.$results[$i][‘productId’].‘" value="’.$results[$i][‘description’].‘">’; ?></span></td>

What Im trying to do is display the “description” field which is where the description for products in stored in a database for a shopping cart. I want it to display the raw html code inside a form input box, this is so I can copy and paste it to other products in the admin section. I tried using a <textarea> comment but couldnt quite get it to work.

If I understand you correctly, then you want the code element.

You could wrap it like this:

<td align="left" class="<?php echo $cellColor; ?>">
<span class="copyText"><code><?php echo '<input type="text" size="20" name="d'.$results[$i]['productId'].'" value="'.$results[$i]['description'].'">'; ?></code></span>

If you’d like to format the display of your code, you can also use the pre element in addition to allow you having the code display exactly how you specify to control the whitespace and carriage return.

<td align="left" class="<?php echo $cellColor; ?>">
<span class="copyText"><pre><code><?php echo '<input type="text" size="20" name="d'.$results[$i]['productId'].'" value="'.$results[$i]['description'].'">'; ?></code></pre></span>

You also need to be aware that you have to use HTML entities inside your code element, so instead of using “<” and “>” you’d use < and &gt;.

Hi guys. love how fast you get replies here!

I started reading about htmlentities and tried inserting that into the line in different place but no luck, no errors the page just wouldnt work.

Ive tried Kohoutek’s 2 lines also but they both generate similar to what I got already, the first few chars from the “description” field in the DB are displayed in the form box and then after that it generates html below this form box.

I dont really know much about html or php, I just fumble my way around :slight_smile: but Im learning all the time.

<td align="left" class="<?php echo $cellColor; ?>"><span class="copyText">
<input type="text" size="20" name="d<?php echo $results[$i]['productId']; ?>" value="<?php echo htmlentities($results[$i]['description']); ?>"></span></td>

Awesome Dan worked exactly as I wanted, thanks so much guys.