I want to read out a text width JS on a website as it is shown not how it is delivered by PHP or anything else. e.g. delivered text:
ABCDE
rendered text (that I want to have):
AB
CD
E
Does anybody know a way ?
thanks for your help!
I want to read out a text width JS on a website as it is shown not how it is delivered by PHP or anything else. e.g. delivered text:
ABCDE
rendered text (that I want to have):
AB
CD
E
Does anybody know a way ?
thanks for your help!
Not sure if I have read what you're asking correctly but are you talking about displaying code as text on a page? If so you should be able to use the <pre> </pre>
HTML elements to do this.
tags though, see here: http://www.w3schools.com/html5/tag_phrase_elements.asp
– Barlow1984
Aug 31 '12 at 08:52
A generic function to split up a string into chunks of [n] characters, using a [splitter]:
function splitByX(str,n,splitter){
n = n || 2;
splitter = splitter || ' ';
var x = [];
for (var i=0;i<str.length;i+=n){
x.push(str.slice(i,i+n));
}
return x.join(splitter);
}
var strFormatted = splitByX('ABCDEFGHIJ') //=> "AB CD EF GH IJ"
,strFormatted2 = splitByX('ABCDEFGHIJ',3); //=> "ABC DEF GHI J"
,strFormatted3 = splitByX('ABCDEFGHIJ',3,'<br>');
//=> "ABC<br>DEF<br>GHI<br>J"
For a <span>
with the text within:
var receivedSpan = /*[retrieve the span using a DOM method]*/;
receivedspan.innerHTML = splitByX(receivedspan.innerHTML,2,'<br>');
Alternatively you can style the span in PHP:
<span style="white-space:pre">AB\nCD\nE</span>