Finding the Position of a Substring in a String in PHP


Use strpos() to find the first occurrence of a substring within a string.

Source Code

$myString = "Hello, world!";
$pos = strpos($myString, "world");
if ($pos !== false) {
    echo "The position of 'world' is: " . $pos;
} else {
    echo "'world' not found.";
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments