Re: Parsing a document

From: Date: Sat, 28 Oct 2000 19:45:42 +0000
Subject: Re: Parsing a document
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-22482@lists.php.net to get a copy of this message
This is how I would go about doing it... I'm not sure how it's deliminated (ie what seperates the fields) <? $fp = fopen('/path/to/file','r'); while(!feof($fp)){ $line = trim(fgets($fp,4096)); /// /// /// $line is ONE line of the file - processed /// sequencially - do your ereg/explode/split /// on this variable. /// /// if($line == $match){ $zips[] = $line; } } fclose($fp); while(list($key,$val) = each($zips)){ $sql = "INSERT INTO zips (zip) VALUES ('$val')"; $r = mysql_query($sql); } ?> --Joe On Sat, Oct 28, 2000 at 03:39:58PM -0400, Adam Montague wrote: > How does one go about parsing a document in PHP to extract certain info? For instance, I have > a document opened with fopen, and read and stored as a variable. How do I parse that variable and > save all zip codes in it as an array, or write them to a file, or something? I can do an ereg() to > find the zip codes, but how do I actually save them all? > > Thanks in advance > Adam ================================================================================ = Joe Stump joestump98@yahoo.com http://www.miester.org = ================================================================================ "Real programmers don't comment their code. It was hard to write, it should be hard to understand."

« previous php.general (#22482) next »