Home > database >  How do you prevent <br> tags from displaying in textarea?
How do you prevent <br> tags from displaying in textarea?

Time:12-02

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.

CodePudding user response:

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>

CodePudding user response:

You can replace the
with &#13;&#10;&#13;&#10;

Line Feed and Carriage Return are HTML entitieswikipedia. This way you are actually parsing the new line ("\n") rather than displaying it as text.

Example:

    <textarea cols='60' rows='8'>3 Pants : White one.&#13;&#10;&#13;&#10;Hem: $50.00</textarea>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

CodePudding user response:

Try this:

$textarea = str_replace('<br>', '\n\r', $textarea);
  • Related