Dynamic Javascript File newline and carriage return
I am building a JS page dynamically with php using .htaccss to make .php to .js
Everything works fine from JS output.
IE
$data = array('one', 'two');
foreach($data as $d){
echo "document.write('This is a test for array item ".$d."'); \r\n";
}
The problem is that it outputs everything on one line, i.e.
document.write('This is a test for array one');document.write('This is a test for array two');
No matter what I have tried, I cannot get it on top of two lines.
Any ideas?
a source to share
Edit: It looks like I misunderstood the question - he was having problems with translations in his JS, not his final HTML.
Your JavaScript breaks out on separate lines because of the "\ r \ n" at the end of the line, but then you output plain text to your HTML document. HTML does not break lines unless you are in a preformatted block (like "<pre>"), or you give it an explicit break (like "<br>").
You probably want your code to look like this:
foreach($data as $d){
echo "document.write('This is a test for array item ".$d."<br>'); \r\n";
}
Just be very careful with your data - inserting random strings into your HTML is a quick way to get security holes.
a source to share