format text in textarea - html

I need to display the text retrieved from the database in the <textarea> tag. But the thing is that i get this text from db with html tags, like:
The line number 1<br>
The line number 2<br>
The line number three<br><br>
But when i do:
<textarea>mytext</textarea>
Inside the textarea box i get exatly the same text will all the tags, like
The line number 1<br>
The line number 2<br>
The line number three<br><br>
htmlspecialchars didn't help. It just made it to display entities instead of formatted text, without any tags as if it was show on the web page
What I need is just to show formatted text without possibility to edit it.
How can I accomplish this?

You can use following:
I hope it helps.

I'm not sure why you have HTML tags like <br> in your database. Did you use nl2br before saving or something? You shouldn't do that. Replace them by fullworthy newlines and it'll work in the textarea.
If you intend to present them in a non-textarea afterwards, then you're allowed to use nl2br or like (only at the point of presentation!), or just use CSS white-space: pre instead.

Related

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

Truly selecting in HTML tags in Vim

In an HTML doc say I have this:
<p>
fdhjfkdj hfkjdfhkjdfhkjdh dfhdkf kjdh kjdhkjdhk
fhkdj hdjfhjkdh kjdh kjdf jkdhf d
jfdfhkdjfhkjdf
fjdj fhkd fdhfkjd hfkjdfhkjdf kdhfd
fdhjkfjk dhjdfhkjdf kjdfhdk fhdk
</p>
If I do the normal vit command in vim it'll select the text inside if I yank it, but if I try to do anything such as tab over or run gqit affects the entire <p>. For example, doing vit then gq ends up looking something like
<p> fdhjfkdj hfkjdfhkjdfhkjdh dfhdkf kjdh kjdhkjdhk lkd sldj lks jlkdf
jlsdkf jlsdf jdl dlsjl fhkdj hdjfhjkdh kjdh kjdf jkdhf d jfdfhkdjfhkjdf fjdj
fhkd fdhfkjd hfkjdfhkjdf kdhfd fdhjkfjk dhjdfhkjdf kjdfhdk fhdk </p>
Indenting it wont indent the text, but the whole tag. How do I truly select on the the text inside so I can run commands on it like the ones above?
That's because the inner HTML of the paragraph starts immediately after the starting <p> tag, so it includes the newline character immediately after it (which you'll also see after vit). As you've recognized, reformatting and indenting are line-based, so that single character counts.
To make the text object work like you want, you need to move to the start of the selection (o), then reduce it to the next line (easiest with j; for indenting and formatting, the exact start column isn't important, anyway). So the sequence for reformatting would be:
vitojgq
If you want something quicker, you need to write your own text object. Have a look at my CountJump plugin, or the textobj-user plugin; they can help with defining one.

Showing multiple lines of text through EL

I am having problem displaying a text with multiple lines. For example, the user can type their text in a textarea in a registration form and the text can be of more than one line i.e. he can hit the Enter (return) key to insert line breaks.
On one page, if I want to show the text that he typed and I use a textarea to display (with EL), it displays the way user had entered initially.
But on another page I need this text be shown in paragraph format (using <p> tag). On this page, when I display the value that the user entered while registering, it does not have the line breaks i.e. it displays in a single line rather than with multiple lines as was entered by the user.
I already tried displaying the text through EL within a <p> tag and using a <c:out> tag of the JSTL within a <p> tag.
Some code that I tried:
Trial-1:
<p>${product.description}</p> //Doesn't show line breaks
Trial-2:
<p><c:out value="${product.description}" /></p> //Doesn't show line breaks too
How can I fix this?
Did you view the source sent to the browser ? Please try
<p><pre>${product.description}</pre></p>
Right now I can think of something as to replace the \r\n sequence in the product.description string with <br /> with help of scriptlets or fn JSTL (function) tag
Idea Courtesy: SO Answer.

Flex4.6 StyleableTextField ignores <br> and <p> tags

I've got a StyleableTextField in my mobile project, which gets filled with html text using the .htmlText property.
The tag is working fine for me, but simple line breaks or paragraphs are simply ignored. What can I do about that?
Basically, the simplest HTML will just be displayed as a single line:
textField.htmlText = "<p>this should be the first line</p><p>this the second one</p>";
Again, the output is a single line.
The Flex 3 doc states that those tags are definitely supported, so I reckon they simply removed it in the newer versions (which is kinda ridiculous!).
I don't want to use the stagewebview, so what other ways to I have to properly format HTML using the StyleableTextField, or is there a simple replacement for the aforementioned tags?
Thank you very much guys!
Make sure that multiline is set to true, otherwise it will treat it as a single line of text, effectively ignoring the formatting.

<input> multi-line capable via CSS

Is there a way to get an <input />-field in HTML to wrap lines if the text is longer than the field using CSS? I don't want to use <textarea /> as I want to avoid users entering hard line-breaks by pressing enter.
No, sorry. <input type=text> is single line by definition. See the W3C document Forms in HTML Documents:
text
Creates a single-line text input control.
Using Dojo's Dijit TextArea form control, based off TextArea, you can have an input field which begins as a single line and expands as the user adds to it.
See its documentation.
You can't do what you want with CSS alone, but you could use JavaScript to prevent the user from entering line breaks in a <textarea> field.
Look at this,
http://www.echoecho.com/htmlforms08.htm
The wrap options are the most tricky part of text areas.
If you turn wrap off the text is handled as one long sequence of text without linebreaks.
If you set it to virtual the text appears on your page as if it recognized linebreaks - but when the form is submitted the linebreaks are turned off.
If you set it to physical the text is submitted exactly as it appears on the screen - linebreaks included.
Your best bet is use a textarea (with autogrow capabilities if you like), and then strip out the new lines when the form is submitted. Using php it would be something like this:
$text = str_replace(array("\n","\r"),'',$_POST['text_field']);
This would have the desired effect of blocking newline characters. As others have pointed out it's not really possible to get multi-line input in an input field.