How do I replace open characters with <br/> tags in a string?

Asked 2 years ago, Updated 2 years ago, 34 views

I want to change all the open characters in the string to br tag.

For example,

 "This is man.

     Man like dog.
     Man like to drink.

     Man is the king."

I don't know how to use these strings "This is man<br /><br />Man like dog.<br />Man like to drink.<br /><br />Man is the king." I want to change it like this. Please tell me what to do.

javascript php

2022-09-22 22:07

2 Answers

I'll write a regular expression str = str.replace(/(?:\r\n|\r|\n)/g, '<br />'); You can do it in this way.


2022-09-22 22:07

nl2br


2022-09-22 22:07

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.