おそらく、ハンドの開始時にすべてのプレーヤーを特定する必要があります。おそらく正規表現が文字列検索の最良の方法ですが、PHP Explode で試してみます。
<?php
/**
* Input Strings
**/
$GameString = "Player 1 ($630) Player 2 ($578) CLICKK
($507) Player 5 ($600) Player 6 ($621)";
$PostBlindString = "Player 1 posts (SB) $3 Player 2 posts (BB) $6";
$data = explode( ")", $GameString );
$players = array();
/**
* Get the Small Blind Player Name
**/
$SmallBlindPlayer = trim(
substr( $PostBlindString, 0,
strrpos( $PostBlindString, " posts (SB)"
)
)
);
echo $SmallBlindPlayer;
// (Echos 'Player 1' )
/**
* Go through each exploded string
* find it's name before the bracket
**/
foreach ( $data as $p ) {
if ( $p !== '' )
$players[] = trim(substr( $p, 0, strrpos( $p, "(" )));
}
/**
* Our Resulting players
**/
print_r( $players );
Array
(
[0] => Player 1
[1] => Player 2
[2] => CLICKK
[3] => Player 5
[4] => Player 6
)
/**
* Game states array
* when we know someone's
* position, we can assign it
* through some loop
**/
$gameStates = array (
"SB",
"BB",
"UTG",
"MP",
"CO",
"BTN"
);
/**
* Find the small button player
**/
for ( $x = 0; $x < count($players); $x++ ) {
if ( $players[$x] == $SmallBlindPlayer )
echo $players[$x] . " This player is the small blind!";
}
/**
* Go through them, as assign it
* loop back to start if the player
* is late in the array
**/
$PlayerPositions = array();
$LoopedThrough = false;
$Found = false;
$FoundAt = 0;
$c = 0;
for ( $x = 0; $x < count($players); $x++ ) {
if ( $players[$x] == $SmallBlindPlayer && !$Found ) {
$PlayerPositions[$players[$x]] = $gameStates[$c];
$Found = true;
$FoundAt = $x;
} else {
if ( $Found ) {
if ( $x != $FoundAt )
$PlayerPositions[$players[$x]] = $gameStates[$c++];
}
if ( $Found && !$LoopedThrough ) {
$x = -1; $LoopedThrough = true;
}
}
}
/**
* Print the "merged" arrays
**/
print_r( $PlayerPositions );
Array
(
[Player 1] => SB
[Player 2] => BB
[CLICKK] => UTG
[Player 5] => MP
[Player 6] => CO
)
?>
私の考えでは、ここから、$Gamestates
プレイヤーが「見つかった」場所で状態を示し、新しい文字列に追加するか、元の文字列をsubstr_replace$Gamestring
のようなものに置き換えることができることを知って、プレイヤーリストを反復処理できます。
さらに、プレーヤー名を収集するときに同じ時点でスタックサイズを収集して、単純に新しいものを作成する$GameString
こともできます-関係なく、配列にそれらがあるので、それらでできることはもっとたくさんあります.