The GeneralUtility class in TYPO3 CMS provides a variety of useful functions for developers. One such function is trimExplode, which allows you to split a string into an array and trim each element.
Here are a few examples of how you might use trimExplode in your TYPO3 CMS project:
Example 1: Splitting a string of tags
Suppose you have a string of tags separated by commas, like this:
$tags = "apple, banana, cherry, durian";
If you want to convert this string into an array of tags, you can use trimExplode like so:
This will create an array with four elements: "apple", "banana", "cherry", and "durian". Note that the second argument to trimExplode is the delimiter used to split the string, and the third argument tells it to remove any whitespace around each tag.
Example 2: Parsing a list of email addresses
Suppose you have a textarea where users can enter a list of email addresses, like this:
$emailList = "john@example.com
jane@example.com
bob@example.com";
If you want to convert this list into an array of email addresses, you can use trimExplode like so:
$emailArray = GeneralUtility::trimExplode("
", $emailList, true);
This will create an array with three elements: "john@example.com", "jane@example.com", and "bob@example.com". Note that the delimiter in this case is a newline character, and the third argument tells trimExplode to remove any whitespace around each email address.
In both of these examples, we've used the GeneralUtility class and the trimExplode function to easily convert a string into an array. This function is part of the TYPO3 CMS core utility library.
PHP TYPO3\CMS\Core\Utility GeneralUtility::trimExplode - 30 examples found. These are the top rated real world PHP examples of TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode extracted from open source projects. You can rate examples to help us improve the quality of examples.