Reply to Re: Problems with regex

Your name:

Reply:


Posted by jamen on 10/13/87 11:30

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>";
}

[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

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