Example 1 — Find a Word in a Sentence
The simplest use: get the index where a word starts.
<?php
$text = "Hello World";
$pos = strpos($text, "World");
echo $pos, PHP_EOL; How It Works
- Store a sentence in a variable.
- Search for "World".
- Counting from 0, the "W" is at index 6.
- echo prints the position.

