note 72550 deleted from function.parse-ini-file by bobby

From: Date: Tue, 27 Mar 2007 21:03:18 +0000
Subject: note 72550 deleted from function.parse-ini-file by bobby
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-124857@lists.php.net to get a copy of this message
Note Submitter: php at matosconsulting dot com ---- Before I was aware of this function, I actually wrote one myself. Just in case anyone could use it... <?php $filename = 'sample.txt'; echo "I am reading this file (click to view raw data): <a href='$filename'>$filename</a><br><br>"; $lines = file($filename); //read the entire file into $lines $numlines = count($lines); for ($x=0;$x<=$numlines;) //let's loop through every line { if (preg_match('/\[(.*?)\]/',$lines[$x],$match)) //if line starts with [ and ends with ]... { $section = $match[1]; //section is [whatever] $x++; while (!preg_match('/\[(.*?)\]/',$lines[$x]) && $x<=$numlines) //while we dont' see another [xxxxx] { $thisline = trim($lines[$x]); //trim whitespace if (strlen($thisline) > 0) //if it's not a blank line... { list($key,$value) = split('=',$thisline); $values[$section][$key] = $value; //save values into array } $x++; } } } ?> $values contains the data...and coincidentally in the same way that PHP's function returns it....

« previous php.notes (#124857) next »