[TYPO3-core] RFC #9779: t3lib_div::trimExplode limit parameter leads to wrong result with non-empty requirement
Benjamin Mack
benni at typo3.org
Tue Mar 3 14:14:26 CET 2009
Hello,
On 03.03.2009 14:04 Uhr, Franz Holzinger wrote:
>> Imagine ",,,,anc2,sr2,,str3" and you get an empty array after removing
>> trimmed items with a limit of 3.
> But an additional leading IF could consider also this case in order not
> to slow its execution speed down. This is why the §limit parameter is
> used at all, to have a benefit in speed.
Sounds good! I like this.
@Ingo: I really want to have the drawbacks and the behaviour etc.
document in the comment header of the function. Can we do that?
Another idea would be to do a pre-cleanup in the string before it gets
exploded:
$string = trim($string, ',');
$string = str_replace(',,', ',', $string);
Don't know though if it would improve anything on large strings.
All the best,
Benni.
>> If you have a very long string and you need that (unusual) behaviour,
>> it'd make more sense to do a manual explode with a limit and an
>> implode again before you let it run through the trimExplode.
> In the former versions of TYPO3 the execution speed has been almost the
> same for explode or t3lib_div::trimExplode. The parameter
> $onlyNonEmptyValues won't be needed in many cases. This function is
> normally called to trim a big list of parameters entered in TypoScript.
>
>> Do you have a use-case for that scenario?
> You could want to get the first 3 lines out of a long text string read
> in from a file and explode it over the "\n" return character. And then
> display it without leading or trailing spaces. The first lines normally
> contain header information.
>
> - Franz
More information about the TYPO3-team-core
mailing list