Not show <br> tags in text area with nl2br php

lachisolutions :

I'm using nl2br to convert newlines to <br> tag. it works fine. but on post edit, it shows br tag in the textarea. I don't want that in the textarea but also don't want to remove it. can someone help me how to do this? thank you :)

Form

$description_new = nl2br($description); // replacing new lines to <br> tags

<div class="form-group">
  <label for="description" class="mb-2">Describe your job - please be as detailed as possible:</label>
  <textarea name="description" placeholder="I'm looking for..." rows="4" maxlength="2500" id="description" class="form-control" required><?php if (isset($job['description'])) echo $job['description']; ?></textarea>
  <div class="form-errors <?php echo isset($errors['description']) ? 'filled' : ''; ?>"><?php echo $errors['description'] ?? ''; ?></div>
</div>
user11854874 :

This paragraph is from php.net : "nl2br — Inserts HTML line breaks before all newlines in a string". <br> are inserted that means if you have: 'I \n love\n spaghetti.' the function will return: 'I <br>\n love<br>\n spaghetti.'. This means you can still remove the <br> tags from your textarea if you always add new breaks.

But if you want to remove the <br> just for the textarea do:

<textarea><?= str_replace(array('<br />','<br>'),'',$value);?></textarea>

The value still contains the <br> but the textarea doesn't.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=198831&siteId=1