|
Posted by Andrew @ Rockface on 01/12/06 12:34
Gordan wrote:
> Hi
>
> I have an array with following values:
> 419;
> 20;
> 19;20;21;
> 18;30;
> 17;20;25;
> 16;26;
> 16;17;20;21;22;34
>
> I would like to find out in how many keys there is "19;". If I simply search for
> "19;" it will also match "419;" witch is of course wrong. I tried to write a
> regexp but can't seem to pull it off. :-( Could somebody please assist me with
> that regexp
Someone will probably come up with a better regex but try:
<?php
$foo = array(
"20;",
"419;",
"19;20;21;",
"20;19;21;",
"21;20;19;",
"19;",
"194;",
"18;30;",
"17;20;25;",
"16;26;",
"16;17;20;21;22;34"
);
foreach ($foo as $bar) {
if (preg_match("/^19;|;19;/", $bar)) {
echo $bar."<br>\n";
}
}
?>
This matches:
19;20;21;
20;19;21;
21;20;19;
19;
--
Andrew @ Rockface
np: Naked Raygun - Metastasis [stopped]
www.rockface-records.co.uk
Navigation:
[Reply to this message]
|