PHP/Javascript: Need help removing line break from code
- by Josh K
I am trying to get names from a .txt file. I am using file('filename.txt') but if i use a php for loop to try and trim the names, it comes out on multiple lines:
This is the actual line that prints the javascript (NOTE: I am going to be putting these names into a select box, if you can fix the problem at hand the rest of the code should work so unless you a big problem with it you don't need to comment)
<?php
for($i=1; $i < 27; $i++){
echo "selbox.options[selbox.options.length] = new Option('".lines[$i]."','".$lines[$i]."');\n";
}
?>
Heres how it comes out on the browser:
selbox.options[selbox.options.length] = new Option('Djamal ABDOUN
','First1 Last1
');
selbox.options[selbox.options.length] = new Option('Chadli AMRI
','First2 Last2
');
I need those to be on one line so i dont get a unterminated string literal js error
Any ideas on what i can do here?
EDIT: Oh i should probably mention, the $lines var is initiated like this:
$lines = file('filename.txt');
and inside that file i have formatted like this
First1 Last1
First2 Last2
First3 Last3
etc. and i hit delete after each Last name until the next first name is touching, then hit enter to put it on a new line (Editor is notepad++)