Re: Read one word in file

From: Date: Thu, 05 Apr 2001 23:52:09 +0000
Subject: Re: Read one word in file
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-47347@lists.php.net to get a copy of this message
This is how I would do it ... <? $fp = fopen('/path/to/file','r'); while(!feof($fp)) { $line = trim(fgets($fp,4096)); if(strlen($line)) { $arr = explode(' ',$line); $numbers[] = $arr[0]; // if you want to make it remove the .'s then // do $numbers[] = str_replace('.','',$arr[0]); } } for($i = 0 ; $i < sizeof($numbers) ; ++$i) echo $numbers[$i]."\n"; ?> --Joe On Thu, Apr 05, 2001 at 04:50:37PM -0700, Andrew V. Romero wrote: > I have a php script that reads a file that looks something like this: > > 1. Question One goes here: > 2. Question two goes here: > > I need someway to have the script just read either the 1. or just the 1 > When I first made the script I just had the program read the line using > $questionBuffer = fgets($wq, 4096); and then I got the number by using > a substring message: $currentQuestion = substr("$questionBuffer",0,1); > and this works fine until I hit questions like 10 11... > So how should I go about just getting the question number, ideally I > would like to just read up until the first space is encountered. Is > there a function to do that or will I need to create a for loop that > goes through and compares each substring of 1 character to " ", and then > once that " " is found, create a substring up until that " " character > was found? Any ideas? > --Andrew V. Romero > To reply personally, remove all numbers from my address. > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net /******************************************************************************\ * Joe Stump - PHP/SQL/HTML Developer * * http://www.care2.com - http://www.miester.org - http://gtk.php-coder.net * * "Better to double your money on mediocrity than lose it all on a dream." * \******************************************************************************/

« previous php.general (#47347) next »