if (strpos($string, "world") !== false) { echo "The word 'world' was found in the string."; } else { echo "The word 'world' was not found in the string."; }
$string = "Hello world and universe!"; $pos = strpos($string, "world", 7); if ($pos !== false) { echo "The word 'world' was found at position $pos."; } else { echo "The word 'world' was not found in the string."; }In this example, we start searching for the word "world" from position 7 (i.e. after the space following "Hello"). The expected output is "The word 'world' was found at position 12." The JString strpos function is part of the Joomla String package library, which provides a range of utility functions for manipulating strings in Joomla CMS and other Joomla-based applications.