note 72550 added to function.parse-ini-file

From: Date: Wed, 24 Jan 2007 06:34:54 +0000
Subject: note 72550 added to function.parse-ini-file
Groups: php.notes 
Request: Send a blank email to php-notes+get-122098@lists.php.net to get a copy of this message
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.... ---- Server IP: 217.160.72.57 Probable Submitter: 74.237.92.60 ---- Manual Page -- http://www.php.net/manual/en/function.parse-ini-file.php Edit -- https://master.php.net/note/edit/72550 Del: integrated -- https://master.php.net/note/delete/72550/integrated Del: useless -- https://master.php.net/note/delete/72550/useless Del: bad code -- https://master.php.net/note/delete/72550/bad+code Del: spam -- https://master.php.net/note/delete/72550/spam Del: non-english -- https://master.php.net/note/delete/72550/non-english Del: in docs -- https://master.php.net/note/delete/72550/in+docs Del: other reasons-- https://master.php.net/note/delete/72550 Reject -- https://master.php.net/note/reject/72550 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#122098) next »