why this script dont work? (the right place)

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
Angel
Forum Newbie
Posts: 3
Joined: Sat May 25, 2002 8:42 am
Contact:

why this script dont work? (the right place)

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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;
Angel
Forum Newbie
Posts: 3
Joined: Sat May 25, 2002 8:42 am
Contact:

Post 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
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

What's the error? That would help a LOT.
User avatar
NetDragonX
Forum Newbie
Posts: 15
Joined: Sat May 25, 2002 3:00 pm
Location: Southern California

Post 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 :)
Post Reply