preg_matches について少し質問があります。これらの正規表現は非常に理解しにくいので、誰かが正しい awnser を提供してくれることを願っています!
次のテキストがあります。
0A-24-423
しかし、これは次の場合もあります。
0A-242-2
また
0A-2-423
preg_matches を使用してこれらをフィルタリングするにはどうすればよいですか? 使っていました
substr($something, 0,2)
0Aをキャプチャし、
substr($seat, 4,5)
これは24をキャプチャしますが、242を取得すると最後の2をキャプチャしません....
誰かが preg_match でこれを作成するのを手伝ってくれることを願っています!
私が今持っているものをより明確にするために:
foreach($_POST['seats'] AS $seat) {
if ($count > 0) {
$selectQuery .= " || ";
}
$selectQuery .= " ( rowId = '" . substr($seat, 0,2) . "'";
$selectQuery .= " and `order` = " . substr($seat, 3,5) . " ";
$selectQuery .= " and columnId = " . substr($seat, 6) . " ) ";
$count++;
$seat の形式は XXXXXX で、substr を使用すると適切なものを取得できます (例: 0J3017)
このような何かがそれを行う必要があります:
$selectQuery = "SELECT * from seats where ";
$count = 0;
$pattern = "I DON'T KNOW :( ";
foreach($_POST['seats'] AS $seat) {
if ($count > 0) {
$selectQuery .= " || ";
}
preg_match($pattern, $seats, $matches);
$selectQuery .= " ( rowId = '" . $matches[0] . "'";
$selectQuery .= " and `order` = " . $matches[1] . " ";
$selectQuery .= " and columnId = " . $matches[2] . " ) ";
$count++;
$seats は投稿の冒頭で説明されています (形式は次のとおりです)。XX-XXX-XXX
where the first 2 XX are 0[A-Z] (yes the 0 is correct)
where the 3 first XXX are [0-9]
Where the last 3 XXX are [0-9]
編集:これを解決するには2つの方法があります。
オプション1:
$pattern = "/(.*)-(.*)-(.*)/";
または、explode() 関数を使用します。