Page 1 of 1

php problem with javascript

Posted: Sat Nov 06, 2004 5:08 pm
by MMC98DJ
hi everyone, i have a problem with my loop. i get all the data out of the file fine but the javascritp won't work due to carrage returns that the php engine seems to put in. this is the current output:

randImgObj.set2=new Array('images/small_modern/m1.jpg
','images/small_history/m1.jpg
');


when i remove the /n my self teh script works fine

this is my php code
<?php
$line ="test";
$i=1;





$filename="test/test.txt";
$fp =fopen($filename, "r") or die("could not open file $filename");
while (! feof($fp)){

$line =fgets($fp,3000);

$t= "randImgObj.set".$i."=new Array('images/small_modern/".$line."','images/small_history/".$line."');";

$t= trim($t);


print $t;
$i++;
}

this is how the out put should look
randImgObj.set2=new Array'images/small_modern/m1.jpg','images/small_history/m1.jpg');

Posted: Sat Nov 06, 2004 6:05 pm
by rehfeld
trim only trims the left and right ends of a string




Code: Select all

<?php


$lines = file('test.txt');



$i = 1;

foreach ($lines as $line) {
    $line = trim($line);
    echo "randImgObj.set".$i."=new Array('images/small_modern/".$line."','images/small_history/".$line."');"; 
    $i++;
}




?>