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.
FWIW: