-1
これにより、第2に Output 2PHPなぜpreg_matchが通常の出力と異なるのですか?
、そして第一のPHPコード
$bbtext = "<br/><br/>This [color=red]is [b]bold[/b] and this is [u]underlined[/u] and [color=green]this [/color]is in [i]italics[/i] with[/color] a [color=red] red color[/color]";
preg_match_all('/\[color=(.*?)\]/', $bbtext, $matches, PREG_OFFSET_CAPTURE);
print_r($matches);
上記のPHPコードが出力され、 Output 1
、出力される
$pattern = '/abcd/';
$string = 'weruhfabcdwuir';
preg_match($pattern, $string, $matches, PREG_OFFSET_CAPTURE);
print_r($matches);
他のPHPコードでありますPHPコードabcdは、6thのインデックス位置から始まります。 (インデックスは常に0から始まることがわかっています) PHPの出力で正しく動作しています。
最初のPHPコードでは、[色=赤]は5thのインデックス位置から始まります。出力は15と表示されます。
なぜこの相違が発生しましたか出力1?
<br/><br/>This [color=red]is [b]bold[/b] and this is [u]underlined[/u] and [color=green]this [/color]is in [i]italics[/i] with[/color] a [color=red] red color[/color]";
^character offset 15
私たちは何かが欠けています:
「
」は何ですか?空のスペース? –
ありがとう、私はこれを見ていない
– Siva7170