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>";
}
Navigation:
[Reply to this message]
|