Questions tagged [nl2br]

PHP function that inserts HTML line breaks before all newlines in a string

PHP function that inserts HTML line breaks before all newlines in a string

string nl2br ( string $string [, bool $is_xhtml = true ] )

Returns string with <br /> or <br> inserted before all newlines (\r\n, \n\r, \n and \r).

Documentation: https://php.net/manual/en/function.nl2br.php

125 questions
197
votes
13 answers

How to remove line breaks (no characters!) from the string?

This might appear to be a dupe, but rest assured it isn't - I have searched both SO as well as the rest of the web for an answer to my problem and ended up finding the same insufficient "solutions" over and over. Anyhow, here it goes: I'm saving…
Johannes Pille
  • 4,073
  • 4
  • 26
  • 27
92
votes
10 answers

How can I replace newline or \r\n with
?

I am trying to simply replace some new lines and have tried three different ways, but I don't get any change: $description = preg_replace('/\r?\n|\r/', '
', $description); $description = str_replace(array("\r\n", "\r", "\n"), "
",…
theflowersoftime
  • 2,546
  • 3
  • 24
  • 32
44
votes
13 answers

line breaks in a textarea

I know when saving a textarea you can use the nl2br() or str_replace to change the /n to br tags etc. However what im not sure about how to insert line breaks into a textarea. I cant seem to find much about putting the data back into a textarea with…
fl3x7
  • 3,723
  • 6
  • 26
  • 37
43
votes
7 answers

\n vs. PHP_EOL vs.
?

In most cases, as for one interactive website, when we output multiple lines of contents to web client browser, in my opinion,
is much more preferable than other two: \n or PHP_EOL. Else, we need to use "
" to wrap the output…
John Yin
  • 8,057
  • 4
  • 25
  • 25
38
votes
5 answers

How do I use nl2br() in Laravel 5 Blade

So I want to keep linebreaks from the database while using the Blade Template Engine. I came up on the idea using {!! nl2br(e($task->text)) !!} It works. But it looks like a needlessly complicated solution. Is there a better way?
ya-cha
  • 602
  • 2
  • 6
  • 14
14
votes
3 answers

Vue.js show white space (line breaks)

How would I show line space in vue.js. Right now everything is after each other.... Already tried this: https://laracasts.com/discuss/channels/vue/vuejs-how-to-return-a-string-with-line-break-from-database But nothing seems work. Trying this for 3…
Jamie
  • 10,302
  • 32
  • 103
  • 186
12
votes
2 answers

Nunjucks nl2br does not exist?

I need a filter like the Jinja "nl2br", but in the Nunjucks. In the documentation are a mention (https://mozilla.github.io/nunjucks/templating.html), but I searched it in the nunjucks code…
6
votes
4 answers

How to replace tab with   in PHP?

In my database I have the following text: for x in values: print x I want to print this code on my HTML page. It is printed by PHP to the HTML file as it is. But when HTML is displayed by a browser I, of course, do not see text in this form. I…
Roman
  • 124,451
  • 167
  • 349
  • 456
6
votes
7 answers

new line to

in php

I currently have a lot of jokes in a database that are formated with nl2br() which produces... This is just dummy text. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Vestibulum gravida justo in arcu mattis lacinia. Mauris…
bghouse
  • 558
  • 2
  • 8
  • 26
5
votes
2 answers

How to use nl2br and linky filter together in Angularjs?

I am trying to use multiple filters as below,

which renders nothing. However, when I change the order of filters as below

Nirav Gandhi
  • 1,945
  • 1
  • 23
  • 32
5
votes
2 answers

PHP: How to keep line-breaks using nl2br() with HTML Purifier?

Issue: When using HTML Purifier to process user-inputted content, line-breaks are not being translated into
tags. Consider the following user-inputted content: Lorem ipsum dolor sit amet. This is another line.
.my-css-class {
   …
Community
  • 4,922
  • 7
  • 25
  • 37
5
votes
1 answer

Twig nl2br filter not working on entity

I have an Address entity with a __toString() method like this : public function __toString() { $result = $this->getStreet(); if ($this->getStreet2()) $result .= '\n' . $this->getStreet2(); $result .= '\n' .…
Julien
  • 9,312
  • 10
  • 63
  • 86
4
votes
3 answers

Newline Conversion in Submitted Text in PHP

I have a system set up for users to submit their articles into my database. Since it will just be HTML, I don't want to expect them to know to type
every time there's a newline, so I am using the PHP function nl2br() on the input. I'm also…
muttley91
  • 12,278
  • 33
  • 106
  • 160
3
votes
3 answers

Limit amount of br's nl2br shows in a row?

I'm having some problems with a "bb parser" I'm coding. Or, well, not with the parser itself, but the nl2br modifying it. The string from the database is like the following: text text text [code]code code code[/code] text text text Now, nl2br puts…
Fredrik
  • 31
  • 2
3
votes
4 answers

How to use nl2br() to handle string with '\r\n'?

I am retrieving a product description value stored in database from admin through textarea upon form submit. When I select the description from database I get $description = $row['description']; and I would like to echo $description on main page…
Manny Calavera
  • 6,815
  • 20
  • 60
  • 85
1
2 3
8 9