-1
이 초 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 코드
, 를 [컬러 = 빨간색]은 5 인덱스 위치에서 시작한다. 출력은 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