2017-11-26 4 views
-1

Dieser erste PHP-CodePHP warum preg_match Ergebnis von der normalen Ausgabe abweichen?

$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); 

die obige PHP-Code ausgegeben wird, Output 1

Dann andere PHP-Code

$pattern = '/abcd/'; 
$string = 'weruhfabcdwuir'; 
preg_match($pattern, $string, $matches, PREG_OFFSET_CAPTURE); 
print_r($matches); 

ausgegeben wird, Output 2

In zweiter PHP-Code, abcd ist Start von 6th Indexposition. (wir wissen, dass der Index immer bei 0 beginnt). Es funktioniert korrekt auf PHP-Ausgabe.

In ersten PHP-Code, [color = red] ist aus 5. Indexposition starten. aber, Ausgabe wird als 15 angezeigt.

Warum ist dieser Unterschied auf Ausgabe 1 aufgetreten?

+5

Und '

' ist was? Leere Räume? –

+0

danke, ich habe nicht geschaut

Siva7170

Antwort

1

Ich bin mir nicht sicher, warum Sie denken, dass es an Charakter 5 Offset beginnt, 15 richtig zu mir aussieht:

<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 

sind etwas fehlt uns?