Re: Reading from file
| From: | Chris | Date: | Tue, 02 Nov 2010 04:31:30 +0000 |
| Subject: | Re: Reading from file | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-47469@lists.php.net to get a copy of this message | ||
On 02/11/10 14:34, Ethan Rosenberg wrote:
Dear List - Thank you for all your help. Here is another one..... I have a file [/home/ethan/PHP/RecNum] which consists of the number 1005. It also has been "1005". No matter how I do it, it is only recognized as 1. Here is the code. In this case, the file is "1005". $fptr1 = fopen("/home/ethan/PHP/RecNum", "r+"); $recNum = (int)fscanf($fptr1,"%s"); echo $recNum; //which always is 1 If I do not typecast $recNum to int, the value is Array.Right, which is what the manual says as well: http://www.php.net/fscanf If only two parameters were passed to this function, the values parsed will be returned as an array. So you can either do: $line = fscanf($fptr1, "%s"); $recNum = $line[0]; // get the first element in the array as $recNum or while ($line = fscanf($fptr1, "%s\n")) { $recNum = $line[0]; } -- Postgresql & php tutorials http://www.designmagick.com/