Re: Read one word in file

From: Date: Fri, 06 Apr 2001 01:15:14 +0000
Subject: Re: Read one word in file
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-47368@lists.php.net to get a copy of this message
Once you get the first line into an array, you can just use explode on \n, or use a regex that searches for any group of characters that is not a whitespace character, then stops searching once it's found it. As Chris said, there are many many ways of doing it. -- Plutarck Should be working on something... ...but forgot what it was. "Chris Fry" <chris@quillsoft.com.au> wrote in message news:3ACD075A.23BD6EFC@quillsoft.com.au... > You might want to use:- > > $aryQbuff = file("/pathto/filename", "r"); > > You will then have each line of the file in an array. > > Then:- > $intNumLines = count($aryQbuff); > for($i=0;$i<=$intNumLines;$i++) { > $intQnum = explode(".", $aryQbuff[$i]); > // $intQnum now has the question number in it > // Do some processing > } > > This is just one way - there are plenty of others. > > Chris > > "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 > > -- > Chris Fry > Quillsoft Pty Ltd > Specialists in Secure Internet Services and E-Commerce Solutions > 10 Gray Street > Kogarah > NSW 2217 > Australia > > Phone: +61 2 9553 1691 > Fax: +61 2 9553 1692 > Mobile: 0419 414 323 > eMail: chris@quillsoft.com.au > http://www.quillsoft.com.au > > You can download our Public CA Certificate from:- > https://ca.secureanywhere.com/htdocs/cacert.crt > > ********************************************************************** > > This information contains confidential information intended only for > the use of the authorised recipient. If you are not an authorised > recipient of this e-mail, please contact Quillsoft Pty Ltd by return > e-mail. > In this case, you should not read, print, re-transmit, store or act > in reliance on this e-mail or any attachments, and should destroy all > copies of them. > This e-mail and any attachments may also contain copyright material > belonging to Quillsoft Pty Ltd. > The views expressed in this e-mail or attachments are the views of > the author and not the views of Quillsoft Pty Ltd. > You should only deal with the material contained in this e-mail if > you are authorised to do so. > > This notice should not be removed. > > > > -- > 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 >

« previous php.general (#47368) next »