How can the mb_strpos function in PHP be utilized to accurately determine the position of a substring within a UTF-8 encoded string?

When working with UTF-8 encoded strings in PHP, using functions like strpos may not accurately determine the position of a substring due to multibyte characters. To accurately determine the position of a substring within a UTF-8 encoded string, you can use the mb_strpos function in PHP. This function specifically handles multibyte characters and ensures the correct position is returned.

$string = "こんにちは, 世界!";
$substring = "に,";
$position = mb_strpos($string, $substring);

if ($position !== false) {
    echo "The substring '$substring' was found at position: $position";
} else {
    echo "The substring '$substring' was not found in the string.";
}