php/html: Force line breaks to appear inside textarea - html

This should not be that hard but I can't seem to find information on it. How do you get line breaks to appear inside a text area when you are echoing it from the server? In other words what is <some code> in line below?
<text area>first line <some code> second line <some code> third line</text area>
I know how to write out <some code>. I just need to know what it should be. I have tried \n, \r\n, '\n', "\n", \N and variations but cannot get the line breaks to display.
Note: This is not about displaying in HTML so <br> is not what I want. This is not about getting it to display if you are typing it yourself where you can type a carriage return, i.e. :
<textarea>first line
second line </textarea>
When you are outputting from server you cannot use keyboard. This is what code to accomplish above.
Thanks for any suggestions

This is a super old question, but I ran into the same issue ajaxing content into a text area.
Thanks to this answer I used the html code for a new line,
and that worked for me. So basically:
<textarea> Here's my returned text
And it gets two lines </textarea>
which (at least for me) comes out as
Here's my returned text
And it gets two lines

try this
<'p'>firstline<'/p'>
<'p'>secondline<'/p'>
remove comma from p and /p

for display \n in html you should use nl2br() php function .
otherwise you should using "\n" (not "/n") for break the line inside your text ;

You should try \r\n instead of /r/n.

You need to use "\r\n" (with double quotes) when echoing it out from PHP.

Related

Text to HTML conversion in Node Js

I am using nodemailer to send mail from node server. I am getting the content for this mail from MSSQL SQL server which is formatted in plain text format, which meansa there are new line characters in it, however when I send it using nodemailer the newline characters are missing and the whole text looks messed up. The other way is to insert html tags for line break in the plain text and send this works fine. But there is too much mannual work involved what I am looking is for a library or utility which can convert the plain text into the html which I can send using mail.
Is there any liberary for this requirement or a way to do this automatically?
The following will wrap all parts that are separated by more than one newline in paragraphs (<p>...</p>) and insert breaks (<br>) where there is just one newline. A text block without any newlines will simply be wrapped in a paragraph.
template = '<p>' + template.replace(/\n{2,}/g, '</p><p>').replace(/\n/g, '<br>') + '</p>';
So for example, it will take this:
Title
First line.
Second line.
Footer
And convert it to this:
<p>Title</p><p>First line.<br>Second line.</p><p>Footer</p>
The simplest solution is you can replace the new line characters with <br>.
Try
text.split('\n').join('\n<br>\n')
then you are done.
Ok finally this code snippet worked for me -
template = template.replace(/\n/gi, "</p></br/>")
template = template.replace(/<\/p>/gi, "</p><p></br/>")
This was a lot of hit and trial but eventually it worked.

How to add a new line when adding something to a variable

I have this:
data.data.message = 'User created';
app.successMsg = data.data.message + '...Redirecting';
And I want to add a line before the ...Redirecting. I've tried \n, \r, both together but it's not working. I've also read some articles here but they all tell them to use the \n and \r but it's not working for me. I'm just learning so be patient please.
---------------------------------------------------------------EDIT--------------------------------------------------------------
When I use '<br />.... Redirecting' this happens:
Thanks!
You may use <br/> tag to get a new line.
apart of that, you may use any block element(e.g. div) to show it to other line. it actually puts it in another element and block element is always rendered in new line so data goes to next line. you can then apply css to it as well.
If you run it in a browser, then my guess is it's rendered as HTML. HTML ignores newlines, and puts everything on the same line. So you could either put the above text between <pre> brackets, or echo our <br /> where you want a new line. Hope that helps.

Can I embedded HTML tags in an HREF's TITLE? (I need some sort of line break)

It seems not,as they are showing up as cleartext.
I am trying to format a rather large tootlip by inserting <p> and <br>, but, as I say, Chrome treats them as text.
What am I allowed to put into such a tooltip? Anything other than a single string?
Since \n seems to be ignored, is there any way to get a line break into such a string?
You can add symbol for a new line: 
 (\r) or
(\n) to your title.
test
Another option is to find some JavaScript tooltip library.
If you feed them actual line breaks, they will work.
<span title="Two
Liner">Hover here</span>
However, if you need more complex HTML inside, I'd suggest qTip or Bootstrap's tooltips

Force line break (<br/>) in header (<h1>) in Markdown

I'm trying to create a two-line <h1> in Markdown, something along the lines of:
<h1>Title<br/>byline</h1>
The Markdown docs say:
When you do want to insert a <br /> break tag using Markdown, you end a line with two or more spaces, then type return.
Unfortunately, this only seems to work for paragraphs -- if I try it with an <h1> (dots · indicate spaces):
#·Title··
byline
the trailing spaces are ignored and I just get:
<h1>Title</h1>
<p>byline</p>
Can anyone tell me a workaround for this?
P.S. I'm using vanilla Markdown 1.0.1 from the command line.
Turns out the answer is just "use <br/>."
# Title <br/> byline
produces
<h1>Title <br/> byline</h1>
** facepalm **
Just use the alternative syntax for <h1>:
Title··
byline
========
You can also do double space at the end of the line.
For example, this text appears in the same line even though I've written it on the next line.
This appears on a new line.
The thing is there are 2 blank spaces after next line... (Consider those two dots as spaces)
Hope this helps. This also seems better than </BR>.
Reference: http://markdown-guide.readthedocs.io/en/latest/basics.html

Add a linebreak in an HTML text area

How can i add a line break to the text area in a html page?
i use VB.net for server side coding.
If it's not vb you can use
(ascii codes for cr,lf)
Add a linefeed ("\n") to the output:
<textarea>Hello
Bybye</textarea>
Will have a newline in it.
You could use \r\n, or System.Environment.NewLine.
If you're inserting text from a database or such (which one usually do), convert all "<br />"'s to &vbCrLf. Works great for me :)
In a text area, as in the form input, then just a normal line break will work:
<textarea>
This is a text area
line breaks are automatic
</textarea>
If you're talking about normal text on the page, the <br /> (or just <br> if using plain 'ole HTML4) is a line break.
However, I'd say that you often don't actually want a line break. Usually, your text is seperated into paragraphs:
<p>
This is some text
</p>
<p>
This is some more
</p>
Which is much better because it gives a clue as to how your text is structured to machines that read it. Machines that read it include screen readers for the partially sighted or blind, seperating text into paragraphs gives it a chance of being presented correctly to these users.
I believe this will work:
TextArea.Text = "Line 1" & vbCrLf & "Line 2"
System.Environment.NewLine could be used in place of vbCrLf if you wanted to be a little less VB6 about it.
Escape sequences like "\n" work fine ! even with text area! I passed a java string with the "\n" to a html textarea and it worked fine as it works on consoles for java!
Here is my method made with pure PHP and CSS :
/** PHP code */
<?php
$string = "the string with linebreaks";
$string = strtr($string,array("."=>".\r\r",":"=>" : \r","-"=>"\r - "));
?>
And the CSS :
.your_textarea_class {
style='white-space:pre-wrap';
}
You can do the same with regex (I'm learning how to build regex with pregreplace using an associative array, seems to be better for adding the \n\r which makes the breaks display).