note 40645 added to function.strtok

From: Date: Wed, 10 Mar 2004 15:18:18 +0000
Subject: note 40645 added to function.strtok
Groups: php.notes 
Request: Send a blank email to php-notes+get-66556@lists.php.net to get a copy of this message
If you need to parse through a very large delimited text file (such as a word list) combine strtok with file_get_contents. It is much faster than all of the other alternatives i have found (using file() to parse the file into an array, reading the file line by line using fgets()) $dictionary=file_get_contents('path/to/dictionary', 1); //check that the file was read properly if(!$dictionary){ return("read error"); } //dictionary is \n delimited $tok=strtok($dictionary, "\n"); //loop through until we reach the end of the string while($tok){ //do whatever it is you need to do with the $tok string here $tok=strtok("\n"); //get next string } ---- Manual Page -- http://www.php.net/manual/en/function.strtok.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+40645 Delete -- http://master.php.net/manage/user-notes.php?action=delete+40645&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+40645&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#66556) next »