$string1 = 'Hello world'; $string2 = 'Hello'; if (GeneralUtility::isFirstPartOfStr($string2, $string1)) { echo 'Yes, ' . $string2 . ' is the first part of ' . $string1; } else { echo 'No, ' . $string2 . ' is not the first part of ' . $string1; }
$string1 = 'This is a sentence'; $string2 = 'is a'; if (GeneralUtility::isFirstPartOfStr($string2, $string1)) { echo 'Yes, ' . $string2 . ' is the first part of ' . $string1; } else { echo 'No, ' . $string2 . ' is not the first part of ' . $string1; }Output: "No, is a is not the first part of This is a sentence" In this example, we use the same method to check whether the string "is a" is the first part of the string "This is a sentence". However, since "is a" is not the first part of the string, the method returns false and the output reflects that. Package library: TYPO3\CMS\Core\Utility\GeneralUtility