Jump to content

Detect line break in a html textbox?


Cory94bailly

Recommended Posts

I have a textbox on my site and if I enter something like this:

test


test2

 

It will format to this:

test test2

 

 

How can I detect if there is a line break without there actually being one (\n or <br>) and possibly add one?

Link to comment
https://forums.phpfreaks.com/topic/147358-detect-line-break-in-a-html-textbox/
Share on other sites

The \n character is there. To detect it you can use strstr

 

But have no doubt it is there, use nl2br before you output the test to see it (that converts \n to <br>) so it is visible to html.

 

EDIT:

A note though, if you used spaces instead of enters, it could display like that. So instead of \n it is just a bunch of spaces.

Add the wrap attribute to the html tag like this...

 

 <textarea cols="20" rows="5" wrap="hard"> 

Tried, didn't work.

 

 

The \n character is there. To detect it you can use strstr

 

But have no doubt it is there, use nl2br before you output the test to see it (that converts \n to <br>) so it is visible to html.

 

EDIT:

A note though, if you used spaces instead of enters, it could display like that. So instead of \n it is just a bunch of spaces.

I checked in my mysql table and it did not show anything but the stuff with no <br>s or \n s.

MySQL should not show it. When you output the data, do the nl2br. It should convert it.

 

Line breaks are escaped characters. They are not suppose to display, if you view the source of the html file you should notice the breaks.

MySQL should not show it. When you output the data, do the nl2br. It should convert it.

 

Line breaks are escaped characters. They are not suppose to display, if you view the source of the html file you should notice the breaks.

 

I echoed this out:

 

$body = nl2br($news['news_body']);

 

And it just showed nothing..

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.