[TYPO3-core] GeneralUtility::inList() and spaces

JoH asenau info at cybercraft.de
Tue Jul 16 12:09:54 CEST 2013


Am 16.07.2013 12:00, schrieb Xavier Perseguers:
> Hi JoH,
>
>>> Which does not help us here, since we want to compensate for
>>> whitespaces around commas.
>>
>> Still doing it with array functions should be the faster approach,
>> especially with longer CSV lists.
>>
>> $array = array_flip(explode(',', $list));
>> if(
>>      isset($array[$item]) ||
>>      isset($array[' ' . $item]) ||
>>      isset($array[$item . ' ']) ||
>>      isset($array[' ' . $item . ' '])
>> ) {
>>      return TRUE;
>> } else {
>>      return FALSE;
>> }
>
> What about *two* spaces? ;-)

Assuming this to be a serious question: As the third and fourth option 
in the if clause, this should be very uncommon and could be fully 
tackled with trimExplode only, which is time consuming due to a loop 
applying the trim.

But usually there are two ways of writing a CSV list:

1,2,3,4,5
or
1, 2, 3, 4, 5

which could be easily handled by the code above, while any other 
misspelled list would be the problem of the user who did it wrong.

HTH

Joey

-- 
Wenn man keine Ahnung hat: Einfach mal Fresse halten!
(If you have no clues: simply shut your gob sometimes!)
Dieter Nuhr, German comedian
Xing: http://contact.cybercraft.de
Twitter: http://twitter.com/bunnyfield
TYPO3 cookbook (2nd edition): http://www.typo3experts.com


More information about the TYPO3-team-core mailing list