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
3
votes
3 answers

Using nl2br Displays html tags in my textarea

I just started using nl2br in my php site. Basically I am using it to give a nice layout to a 'bio' field in case the user presses enter. Problem is that it stores the exact line break tag
in my database and it does the same when i display the…
John Kariuki
  • 4,966
  • 5
  • 21
  • 30
3
votes
2 answers

How to preserve newline between textarea and database?

I am storing the user input in a text area into a database by using nl2br().
Now the problem is that I do not want to show the "br" tags when I show this input in a text area later but as a new line.
I was using str_replace but this seems…
user1887239
  • 51
  • 2
  • 10
3
votes
4 answers

How to use nl2br to remove \n and add breaks

I'm having some trouble getting nl2br to do what I want. Can someone explain why nl2br doesn't change the \n in the JSON data to < br /> in my PHP? Here is the code: $page = file_get_contents('JSON_FEED_URL'); $page2 = nl2br($page); When I echo…
3
votes
1 answer

Step by step storing textarea mysql php

so i'm getting confused by all the topics about storing and displaying textareas with correct linebreaks and not allowing any HTML markup whatsoever. Right now i am escaping the input, then storing it as a text and then trying to display it with…
Markus
  • 616
  • 1
  • 9
  • 24
3
votes
3 answers

How to show just one newline using nl2br?

I am using nl2br() to convert \n characters to the
tag but I do not want more than one
tag at a time. For example, Hello \n\n\n\n Everybody should become Hello
Everybody. How can I do this?
mTuran
  • 1,846
  • 4
  • 32
  • 58
3
votes
1 answer

nl2br() not working when displaying SQL results

On my Joomla module, we are using the following code to get shouts from the database function getShouts($number, $timezone, $message) { $shouts = array(); $db = JFactory::getDBO(); $query = $db->getQuery(true); $query->select('*') …
Lodder
  • 19,758
  • 10
  • 59
  • 100
3
votes
3 answers

Repopulate nl2br saved content inside textarea without
tags?

When a user save a text from a textarea: bfajsdb fkjasdfasjkdfasdfasdf asdf asdf sdf asdfasdfasdfasdf asd asdf asdf sdfasdfasdf from a textarea using nl2br_except_pre function in codeignter it saves it in the database like : bfajsdb…
Derfder
  • 3,204
  • 11
  • 50
  • 85
3
votes
1 answer

nl2br jQuery function removing characters from each line

I have this very simple br2nl function that I use to take a string and stick it in a textarea. For some reason it's cropping some of the characters off of the ends of some of the lines. Here's my example: http://jsfiddle.net/byZnE/ In this example…
Colin
  • 2,428
  • 3
  • 33
  • 48
2
votes
5 answers

Problems with Textareas, New Lines and nl2br

I'm having trouble getting data out of the database and echoing out in a HTML page textarea. This is the code used to get the data into the database: $_SESSION['content'] = mysqli_real_escape_string($link, strip_tags($_POST['content'],'')); This…
Cristian
  • 6,765
  • 7
  • 43
  • 64
2
votes
2 answers

Confusing Php function result with nl2br

I'm simply experimenting with PHP to prepare me for some upcoming projects and I've encountered a string which won't have
inserted into it even though it is a multi-line string. The code is simple PHP (which I've enclosed in simple html…
Sam
  • 2,771
  • 2
  • 28
  • 41
2
votes
2 answers

strip
(n12br) get from database field

i have a textarea value which its value derived from a field(nl2br) how to strip off "< br/>", so that when i want to edit this field, the "< br />" will not be appeared? //$data["Content"] is the field that has
tags inside $content =…
user723360
  • 77
  • 2
  • 7
2
votes
3 answers

Using nl2br with html tags

I use nl2br when displaying some information that is saved somewhere, but when HTML tags are used I want not to add
tags for them. For example if I use
it will be transformed to
Alex Emilov
  • 1,243
  • 4
  • 19
  • 25
2
votes
0 answers

How do I preserve whitespace when entering data to a database

I am developing a web application in PHP using the Laravel framework. One of the tables in my database is an 'Articles' table which has a content field. A user of the website enters text into a text area and this is inserted into a database using…
Alex Naughton
  • 165
  • 3
  • 11
and inside
tags inside it where I am displaying the retrieved data from the backend. Before saving my data to database, I used this to convert \n and \r into
tags: $data = nl2br($request->data); $data =…
senty
  • 12,385
  • 28
  • 130
  • 260
2
votes
2 answers

Yii2 - Textarea does not show linebreaks

I'm wondering about that the default textarea of Yii2 does not show newlines per default. And the Yii2 model does not save the newlines into the DB. I didn't found anything in the Yii2 documentation, so hopefully you guys can help me - this is more…
pixel-shock
  • 67
  • 1
  • 9
1
2
3
8 9