On Wednesday, 26 June 2024 at 06:18, Mike Schinkel <m...@newclarity.net> wrote:

>> https://3v4l.org/RDYFs#v8.3.8
>
> Note those seven use-cases are found in around the first 25 results when 
> searching GitHub for "strtok(". I could probably find more if I kept looking:
>
>> https://github.com/search?q=strtok%28+language%3APHP+&type=code
>
>>
>
> Regarding explode($delimiter, $str)[0] — unless it is to be special-cased 
> during compilation —it is a really inefficient way to find the substring up 
> to the first character, especially for large strings and/or when in a tight 
> loop where the explode is contained in a called function

Then use a regex: https://3v4l.org/SGWL5

Or a combination of strpos and substr.

I'd bet that both of these solutions would use less memory, and I would guess 
the PCRE one should also be better for performance (although not benchmarked) 
as it is highly specialized in that task.

There are *plenty* of solutions to the specific problem you pose here, and thus 
many different solutions more or less appropriate.

Best regards,
Gina P. Banyard

>

Reply via email to