Page 1 of 1

why this script dont work? (the right place)

Posted: Sat May 25, 2002 9:29 am
by Angel
i use 2 txt files , wanna asing 1 lines of txt1 to fist line of txt 2.
place.txt is as folow:
a
b
c
destination.txt is as folow:
brussels
paris
madrid

this the code i think should work:

<?php
$i= 0;
$fd = fopen ("place.txt", "r");
while (!feof ($fd)) {
$location[$i] = fgets($fd, 4096);
$i++;
}
$i= 0;
fclose ($fd);
$fd = fopen ("destination.txt", "r");
while (!feof ($fd)) {
$place[$i] = fgets($fd, 4096);
$i++;
}
fclose ($fd);
$result_des = array($location[0] => $place[0] , $location[1] => $place[1] ) ;
echo "The first line destination is {$result_des["a"]}.";
?>

result should be brussels

thanx for helping

Posted: Sat May 25, 2002 9:46 am
by volka
how about doing it in one step?

Code: Select all

&lt;?php $fdPlace = fopen ("place.txt", "r");
$fdDest = fopen ("destination.txt", "r");
while ( !(feof($fdPlace)||feof($fdDest)) )  
  $result_des&#1111;trim(fgets($fdPlace, 4096))] = trim(fgets($fdDest, 4096));
fclose ($fdPlace);
fclose ($fdDest);?&gt;

Posted: Sat May 25, 2002 10:24 am
by Angel
echo "The first line destination is {$result_des["a"]}.";
// still erors and no reply of that should give as output "brussels"

thnx for your help anyway

Posted: Sat May 25, 2002 4:09 pm
by Benjamin
What's the error? That would help a LOT.

Posted: Sat May 25, 2002 5:04 pm
by NetDragonX
Hi.

Try this:

Code: Select all

&lt;?php

$result_des = array($location&#1111;0] =&gt; $place&#1111;0], $location&#1111;1]=&gt;$place&#1111;1]); 

$g = 0;
while ( list( $location&#1111;$g],$place&#1111;$g] ) = each( $result_des ) )
{
   echo $location&#1111;$g]." - ".$place&#1111;$g]."&lt;br&gt;";
   $g++;
}
?&gt;
You're welcome :)