Reply to Re: regexp problem

Your name:

Reply:


Posted by Rich on 01/13/06 21:45

"Gordan" <gordanMAKNI@torkul.hr> wrote in message
news:dq57af$j8t$1@news1.xnet.hr...
> 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
>
> thanks
> gordan
>

To count the number of times 19 occurs, something like this would work.

<?
$myarray = array(
"419;",
"20;",
"19;20;21;",
"18;30;",
"17;20;25;",
"16;26;",
"16;17;20;21;22;34"
);

$num = 19;

echo "There are/is ".count(preg_grep("/(?:^|;)$num;/", $myarray))."
occurrence(s) of $num.";
?>


Rich

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация