You are here: Re: regexp problem « PHP Programming Language « IT news, forums, messages
Re: regexp problem

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]


Удаленная работа для программистов  •  Как заработать на 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

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