PHP/Javascript: Need help removing line break from code
Posted
by Josh K
on Stack Overflow
See other posts from Stack Overflow
or by Josh K
Published on 2010-05-18T13:52:47Z
Indexed on
2010/05/18
14:00 UTC
Read the original article
Hit count: 250
JavaScript
|php
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++)
© Stack Overflow or respective owner