Example 1 — Compare From an Offset
Check whether the text starting at position 6 equals "World".
<?php
$text = "Hello World";
echo substr_compare($text, "World", 6), PHP_EOL; How It Works
- Pick an offset. Position
6is where "World" begins. - Compare. PHP compares the rest of the string with the needle.
- Equal parts. Both are
"World". - Get 0. A result of
0means they match.

