You are here: Re: Problems with regex « All PHP « IT news, forums, messages
Re: Problems with regex

Posted by pstidsen@gmail.com on 10/21/05 02:08

jamen wrote:
> Peter Stidsen wrote:
>
> > $string = "(;GM[1]FF[4]CA[UTF-8]AP[CGoban:2]ST[2]
> > RU[Japanese]SZ[19]KM[0.50]TM[600]OT[25/240 Canadian]
> > PW[winifred]PB[artipode]WR[8k]BR[9k]DT[2004-03-05]PC[The Kiseido Go Server
> > (KGS) at http://kgs.kiseido.com/]RE[W+115.50] (...)"
> >
> > From this I need to find a way to:
> > $pw = "winifred"
> > $pb = "artipode"
> > $wr = "8k"
> > $br = "9k"
> > $dt = "2004-03-05"
> > $re = "W+115.50"
> > $pc = "The Kiseido Go Server (KGS) at http://kgs.kiseido.com/"
>
> $cnt = preg_match_all("/(.{2})\[([^\]]*)\]/", $string, $matches);
> $result = array();
>
> // put it in an array for better access
> for($i=0; $i<$cnt; $i++){
> $result[$matches[1][$i]] = $matches[2][$i];
> }
>
> //Then you can pick your variables..
> // echo $result['PW'];
>
>
>
> // display them all
>
> foreach($result as $key=>$value){
> echo "$key = $value<br>";
> }

 

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

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