Skip to content
Advertisement

How do you prevent tags from displaying in textarea?

I am saving this string into my sql db:

   $receipt.= "$tempQty $tempItem : $tempColor :<br> 
                        $tempService <br>
                        &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp Item Total: $$tempPrice 
                        <br><br>";

This displays fine in a table:

3 Pants : White

Hem: $50.00
Press: $65.00

Item Total: $115.00

But when I display it in a textarea it shows up like this:

3 Pants : White <br>
                        Hem: $50.00
Press: $65.00 <br> 
                        Item Total: $115.00 <br><br>

How can I get the textarea to keep the formatting but not show the <br> tags.

Advertisement

Answer

You would want to strip out the <br> tags and the extra space. Here’s a way to do it by splitting the array by <br>, trimming the array parts, then joining it back together with n.

<?php
$receipt = explode("<br>", $receipt);
foreach ($receipt as $n => $r) $receipt[$n] = trim($r);
$receipt = implode("n", $receipt);
?>    

<textarea cols='60' rows='8'><?php echo $receipt;?></textarea>
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement