Jump to content

Replacing Multiple Line Breaks


ldsmike88

Recommended Posts

I have a line of code that looks something like this:

 

var myTextareaValue = textareaValue.replace('\n','<br/ >');

 

That works fine when I only have one line break at a time. But if I have multiple line breaks it only puts one <br/ > tag in instead of two or three. How can I make it so it will put in the right amount of break tags. Thanks!

 

Michael

 

(I know my break tags in this forum aren't formatted correctly, but if they are they actuly are break tags and you can't see them.)

Link to comment
https://forums.phpfreaks.com/topic/42037-replacing-multiple-line-breaks/
Share on other sites

change

var myTextareaValue = textareaValue.replace('\n','<br/ >');

 

to

 

var myTextareaValue = myTextareaValue.replace(/\n/g, /<b r>/ );

 

 

The g switch makes the changes global.

I'm not certain if you can escape the forward slash in the <b r /> replacement section

but if you can it'll probably look like /<br \/>/

I added a space in the br to stop the line from breaking

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.