php problem with javascript

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
MMC98DJ
Forum Newbie
Posts: 1
Joined: Sat Nov 06, 2004 4:56 pm

php problem with javascript

Post 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');
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post 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++;
}




?>
Post Reply