Fwd: [PHP] Help with Arrays
| From: | Pushpinder Singh Garcha | Date: | Fri, 28 Feb 2003 01:01:15 +0000 |
| Subject: | Fwd: [PHP] Help with Arrays | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-137493@lists.php.net to get a copy of this message | ||
Begin forwarded message:
From: Pushpinder Singh Garcha <pgarcha@adelphia.net> Date: Thu Feb 27, 2003 7:57:38 PM US/Eastern To: olinux <olnx@yahoo.com> Subject: Re: [PHP] Help with Arrays Thanks My question was that each line of the file should be stored as one element of the array. This is because, I need to compare each line of the text file against some user values. TIA --Pushpinder On Thursday, February 27, 2003, at 04:33 PM, olinux wrote:Pushpinder Singh Garcha _________________________________ Web Architectand what problem is that?> how about just using the example? http://www.php.net/manual/en/function.file.php $lines = file ('http://www.example.com/'); // Loop through our array, show html source as html source; and line numbers too. foreach ($lines as $line_num => $line) {Pushpinder Singh Garcha _________________________________ Web Architectecho "Line #<b>{$line_num}</b> : " .htmlspecialchars($line) . "<br>\n"; } --- Pushpinder Singh Garcha <pgarcha@adelphia.net> wrote:Hello all I am having some problem with arrays THIS IS THE PHP CODE $temp = file("file.txt");__________________________________________________ Do you Yahoo!? Yahoo! Tax Center - forms, calculators, tips, more http://taxes.yahoo.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.phpif(!$temp) { echo "File could not be read by array !!<br>";exit; } else echo "Array was opened !!<br><br>";$x = count($temp); echo "Array Count is: $x<br><br>"; echo "$temp[0]<br>"; //$P = str_replace("\r\n", "\n" , $temp); echo "<br>First: $temp[0]"; $P_new = explode(" ",$temp); echo "<br>Next: $P_new[0]"; THIS IS THE TEXT FILE CALLLED ''file.txt'' abc111 asd123 aqw234 www234 edr234 vfr456 When I echo "$temp[0]" ... I get abc111 asd123 aqw234 www234 edr234 vfr456 on one straight line, which is weird. I should get it on separate lines.. Also I am unable to separate the lines of the file using the explode(). Any help will be highly appreciated --Pushpinder Pushpinder Singh Garcha _________________________________ Web Architect