Re: Create associative array from comments by preg
| From: | Jonathan Sharp | Date: | Sun, 10 Nov 2002 17:17:30 +0000 |
| Subject: | Re: Create associative array from comments by preg | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-123709@lists.php.net to get a copy of this message | ||
Here's the code...
-js
$string = <<<EOF
<!-- comname 1--!>
value 1
<!-- end comname 1--!>
<!-- comname 2--!>
value 2
<!-- end comname 2--!>
EOF;
preg_match_all('/<!--\s*(.*)\s*--!>\s*(.*)\s*<!--\s*end\s*\\1\s*--!>/i',
$string, $matched);
$array = array();
foreach ( $matched[1] AS $i => $m )
{
$array[$m] = $matched[2][$i];
}
Alawi albaity wrote:
> I have comments like that :
> <!-- comname1 --!>
> value1
> <!-- end comname1 --!>
>
> <!-- comname2 --!>
> value2
> <!-- end comname2 --!>
> Now :
> How can me get associative array like this
> $var["comname1"] = "value1";
> $var["comname2"] = "value2";
>
> can any body help me to do that ?
>
>