boneXXX Posted April 18, 2007 Share Posted April 18, 2007 Exactly the same codes in the same file but acting different ?#@#@!#!@^&$##@ Please look at this codes: <?php $listf = fopen ("./computer.txt", "r") or die("error openning file"); //read the file list($title,$author,$price) = fgetcsv($listf, 4096, "|"); while(!feof($listf)) { echo "$title<br>"; list($title,$author,$price) = fgetcsv($listf, 4096, "|"); } fclose($listf); ?> <?php $listf = fopen ("./member.txt", "r") or die("error openning file"); //read the file list($username,$password,$last_name,$first_name,$email,$organization,$user_level) = fgetcsv($listf, 4096, "|"); while(!feof($listf)) { echo "$username<br>"; list($username,$password,$last_name,$first_name,$email,$organization,$user_level) = fgetcsv($listf, 4096, "|"); } fclose($listf); ?> Please look at the text files: computer.txt Computers in Your Future 2003|Pfaffenberger, Bryan|46 Unix System Management Primer Plus|Horwitz, Jeff|79 Inside Network Perimeter Security|Northcutt, Stephen|83 Cold Fusion MX|Moore, Barry|60 Data Structures and the Standard Template Library|Collins, William J|32 Java Message Service for J2EE|Erdogan, Levent|69 member.txt admin|1234 blabla|abcd AND THE OUTPUT IS: Computers in Your Future 2003 Unix System Management Primer Plus Inside Network Perimeter Security Cold Fusion MX Data Structures and the Standard Template Library Java Message Service for J2EE admin WHY is doesn't read the secon line of the member.txt file?I attached the files if you like to have a closer look [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/47497-reading-from-a-file-it-can-make-you-go-crazy/ Share on other sites More sharing options...
kenrbnsn Posted April 18, 2007 Share Posted April 18, 2007 If you notice, the first code snippet is doing the same thing. You're getting all but the last line from the first file also. Change you code to <?php $listf = fopen ("./computer.txt", "r") or die("error openning file"); //read the file while (list($title,$author,$price) = fgetcsv($listf, 80, "|")) { echo "$title<br>"; } fclose($listf); echo '<hr>'; $listx = fopen ("./member.TXT", "r") or die("error openning file"); //read the file while (list($username,$password) = fgetcsv($listx, 80, "|")) { echo "$username<br>"; } fclose($listx); ?> The manual page states: fgetcsv() returns FALSE on error, including end of file. Ken Link to comment https://forums.phpfreaks.com/topic/47497-reading-from-a-file-it-can-make-you-go-crazy/#findComment-231816 Share on other sites More sharing options...
boneXXX Posted April 19, 2007 Author Share Posted April 19, 2007 Thanks for the reply, I didn't have a problem with the first bits of the codes. But I solved the issue. It was a line ending problem that caused by creating a 2 different .txt files in 2 different systems. The computer.txt was created in Unix and member.txt was created in windows. That caused the problem when I created the member.txt in joe editor the problem is solved. Link to comment https://forums.phpfreaks.com/topic/47497-reading-from-a-file-it-can-make-you-go-crazy/#findComment-233032 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.