Re: regexp; splitting and perl compatible
| From: | Brian Clark | Date: | Thu, 04 Jan 2001 23:05:11 +0000 |
| Subject: | Re: regexp; splitting and perl compatible | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-32758@lists.php.net to get a copy of this message | ||
Hello Chris,
(CH == "Chris Hayes") chayes@antenna.nl writes:
CH> 1) how can i split
CH> "[key1]val[word2]bla[key3]bla"
CH> into a key/val array ?
Ugly as hell, but this works. Maybe a wizard will give you a cleaner
solution.
<?php
$string = '[key1]val1[key2]val2[key3]val3';
$array = explode('[', $string);
while(list($key,$val) = each($array))
{
list($key2, $val2) = explode(']',$val);
$newarray[$key2] = $val2;
}
while(list($key,$value) = each($newarray))
{
print "$key/$value<br>";
}
?>
CH> 2) the php online manual mentions perl-compatible regexps, but
CH> when i try to use one, it complains:
CH> Fatal error: Call to unsupported or undefined function
CH> preg_match()
You using Windows or Unix/Linux? If Windows, that's probably the
reason.
CH> Should i include something? Php.ini?? I get the error in php3 as
CH> well as php4.04.
-Brian