note 78148 added to function.fscanf

From: Date: Sun, 30 Sep 2007 09:56:04 +0000
Subject: note 78148 added to function.fscanf
Groups: php.notes 
Request: Send a blank email to php-notes+get-130943@lists.php.net to get a copy of this message
If you want fscanf()to scan one variable in a large number of lines, e.g an Ipadress in a line with more variables, then use fscanf with explode() <? $filename = "somefile.txt"; $fp = fopen($filename, "r") or die ("Error opening file! \n"); $u = explode(" ",$line); // $u is the variable eg. an IPadress while ($line = fscanf($fp,"%s",$u)) { if(preg_match("/^$u/",$_SERVER['REMOTE_ADDR'])) {$badipadresss++;} // do something and continue scan } ?> Besides, fscanf()is much faster than fgets() ---- Server IP: 195.184.96.15 Probable Submitter: 80.196.190.60 ---- Manual Page -- http://www.php.net/manual/en/function.fscanf.php Edit -- https://master.php.net/note/edit/78148 Del: integrated -- https://master.php.net/note/delete/78148/integrated Del: useless -- https://master.php.net/note/delete/78148/useless Del: bad code -- https://master.php.net/note/delete/78148/bad+code Del: spam -- https://master.php.net/note/delete/78148/spam Del: non-english -- https://master.php.net/note/delete/78148/non-english Del: in docs -- https://master.php.net/note/delete/78148/in+docs Del: other reasons-- https://master.php.net/note/delete/78148 Reject -- https://master.php.net/note/reject/78148 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#130943) next »