Adding new lines in HTML - html

So I'm trying to add text inside a variable and the variable together. But every time I add new text I want it to be added on another line. So when it's spread on multiple lines instead of it being just on one line.
Here is the code I have for it so far. How do I put the old sResults on the lower lines?
sResults = ("You Are The Boss" + sResults)
I've tried using <p> in it but I don't think I'm implementing it right. I tried using \n like in AS3 but that's not working and also <tr> like for tables but I'm still pretty new to HTML and i have no idea.

if you are using javascript then try this way :
sResults = ("You Are The Boss" + sResults)
sResult=sResult+"<br>";

To force a new line in HTML then you need to use the br tag.

Related

Creating new line within a String in HTML

I have string like as follow, which is generated in mvc controller and display in a view within a table cell. S020050A,S020050B,S020050C,S020050D,S020050E,S020050F
,S020050G,S020050H,S020050I,S020050J,S020050K,S020050L
As I want to wrap the text on every 5 words, I have pushed
tag on every 5 words, so that string look like as follow
S020050A,S020050B,S020050C,S020050D,S020050E,S020050F
,S020050G,S020050H,S020050I,S020050J,S020050K,S020050L
I am intended to break the line from there, but in a view it just shows as it is, tag not interpreted as new line but simply as a part of string
I tried putting Environment.Newline and /n as well, when I did this in simple html page, it worked, so I believe it asp.net own mechanism which suppress tag, how I can make tag interpreted as new line?
I could solve it, from controller code (back end) add -> \n instead where you want line break and then in view use this style ->
style="white-space: pre-line"

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.

How to style contents of textarea field with CSS

Is it possible to style the contents of a textarea with CSS? I need to at the very least, insert more space after line breaks.
I want to basically have a new paragraph of text start within the textarea after every carriage return or line break.
You can't style the content of a textarea. All you can do is insert more whitespace manually.
One approach is to replace single carriage returns with double ones
This can be done with either Javascript or PHP...
JS: str.replace("\r\n", "<br />");
http://www.w3schools.com/jsref/jsref_replace.asp
PHP: str_replace("\r\n", "<br />", "whatyouaresearching", "number of replacements you want to make")
http://php.net/manual/en/function.str-replace.php
These are "String Replace" functions. So essentially what we are doing is searching a given string for a certain value and replacing it with another value.
Edit: Looks like I may have incorrectly assumed that the text area would interpret correctly. OP, have you tried yet? If that doesn't work, then try using the HTML Entity Code as the replace value:
http://www.w3schools.com/tags/ref_ascii.asp

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.

How do I put two spaces after every period in our HTML?

I need there to be two spaces after every period in every sentence in our entire site (don't ask).
One way to do it is to embark on manually adding a &nbsp after every single period. This will take several hours.
We can't just find and replace every period, because we have concatenations in PHP and other cases where there is a period and then a space, but it's not in a sentence.
Is there a way to do this...and everything still work in Internet Explorer 6?
[edit] - The tricky part is that in the code, there are lines of PHP that include dots with spaces around them like this:
<?php echo site_url('/css/' . $some_name .'.css');?>
I definitely don't want extra spaces to break lines like that, so I would be happy adding two visible spaces after each period in all P tags.
As we all know, HTML collapses white space, but it only does this for display. The extra spaces are still there. So if the source material was created with two spaces after each period, then some of these substitution methods that are being suggested can be made to work reliably - search for "period-space-space" and replace it with something more suituble, like period-space-&emsp14;. Please note that you shouldn't use because it can prevent proper wrapping at margins. (If you're using ragged right, the margin change won't be noticeable as long as you use the the nbsp BEFORE the space.)
You can also wrap each sentence in a span and use the :after selector to add a space and format it to be wide with "word-spacing". Or you can wrap the space between sentences itself in a span and style that directly.
I've written a javascript solution for blogger that does this on the fly, looks for period-space-space, and replaces it with a spanned, styled space that appears wider.
If however your original material doesn't include this sort of thing then you'll have to study up on sentence boundary detection algorithms (which are not so simple), and then modify one to also not trip over PHP code.
You might be able to use the JavaScript split method or regex depending on the scope of the text.
Here's the split method:
var el = document.getElementById("mydiv");
if (el){
el.innerText = el.innerText.split(".").join(".\xA0 ");
}
Test case:
Hello world.Insert spaces after the period.Using the split method.
Result:
Hello world. Insert spaces after the period. Using the split method.
Have you thought using output buffer? ob_start($callback)
Not tested, but if you'll stick this before any output (or betetr yet, offload the function):
<?php
function processDots($buffer)
{
return (str_replace(".", ". ", $buffer));
}
ob_start("processDots");
?>
and add this to end of input:
<?php ob_end_flush(); ?>
Might just work :)
If you're not opposed to a "post processing"/"javascript" solution:
var nodes = $('*').contents().map(function(a, b) {
return (b.nodeType === Node.TEXT_NODE ? b : null);
});
$.each(nodes, function(i,node){
node.data = node.data.replace(/(\.\s)/g, '.\u00A0\u00A0');
});
Using jQuery for the sake of brevity, but not required.
p.s. I saw your comment about not all periods and a space are to be treated equal, but this is about as good as it gets. otherwise, you're going to need a lot better/more bullet-proof approach.
Incorporate something like this into your PHP file:
<?php if (preg_match('/^. [A-Z]$/' || '/^. [A-Z]$/')) { preg_replace('. ', '. '); } ?>
This allows you to search for the beginning of each new sentence as in .spacespaceA-Z, or .spaceA-Z and then replaces that with . space. [note: Capital letter is not replaced]