Jump to content

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..

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.