note 97426 deleted from function.preg-match-all by danbrown
| From: | danbrown@php.net | Date: | Mon, 19 Apr 2010 14:01:15 +0000 |
| Subject: | note 97426 deleted from function.preg-match-all by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-168398@lists.php.net to get a copy of this message | ||
Note Submitter: l.vardon AT laposte.net
----
3 regexp expressions to extract key, value and comment from ini file line :
// Key name :
preg_match_all('/(.*)\s*=\s*"(.*)"(.*)/U', $line, $arr, PREG_SET_ORDER);
$key=$arr[0][1];
// Value :
preg_match_all('/(.*)\s*=\s*"(.*)"\s*;\s*(.*)/U', $line, $arr, PREG_SET_ORDER);
$value=$arr[0][2];
// Comments :
preg_match_all('/"\s*;\s*(.*)/', $line, $arr, PREG_SET_ORDER);
$comment=$arr[0][1];
Example :
$line is :
mykeyvalue = "this is my "value"" ; Comments here...
$key will be: mykeyvalue
$value will be: this is my "value"
$comment will be: Comments here...
Comment and value may include chars: " ; =
Tested on : PHP Version 5.2.8