Skip to main content
Stack Overflow
  1. About
  2. For Teams

Timeline for answer to str_starts_with and str_ends_with functions in PHP by Vahid Amiri

Current License: CC BY-SA 4.0

Post Revisions

7 events
when toggle format what by license comment
Oct 30, 2020 at 14:32 comment added Jon The accepted (well, currently accepted) solution is already multibyte-safe. It's actually binary-safe, which is an even stronger guarantee.
Apr 17, 2019 at 17:08 comment added Vahid Amiri @ThomasKekeisen Thanks, fixed it.
Apr 17, 2019 at 17:08 history edited Vahid Amiri CC BY-SA 4.0
edited body
Apr 16, 2019 at 16:02 comment added Thomas Kekeisen In startsWith it should be $length = mb_strlen($needle, 'UTF-8');
Sep 8, 2018 at 10:43 comment added dkellner @hanshenrik - it could happen btw, in the very rare case when you look for a string that contains the same bytes as an UTF8 but with half of the last character missing. Like, you have unicode C5 91 (letter "ő") and you look for C5 (letter "Å") it shouldn't give you a match. On the other hand, sure, why would you search an utf haystack for a non-utf needle... But for bulletproof checks, this must be considered a possibility.
May 12, 2018 at 0:06 comment added hanshenrik im pretty sure this is just a waste of CPU. all you need to check, for StarstWith and EndsWith, is just checking that the bytes match, and that's exactly what the accepted answer is doing. this 1 wastes time calculating the number of utf8 characters of the needle, and where the position of the n'th utf8 character of the haystack is.. i think, without being 100% certain, this is just a waste of cpu. can you come up with an actual test case where the accepted answer fails, and this doesn't?
Nov 10, 2017 at 13:59 history answered Vahid Amiri CC BY-SA 3.0

AltStyle によって変換されたページ (->オリジナル) /