5
msdsk
4y

why does preg_split work on my local copy but not on production? WHY DOES IT RETURN LITERALLY NOTHING? IS PHP JUST HELL? AAAAAAAAA

Comments
  • 1
    Preg_split() returns false if there is something wrong, probably what it is doing.

    If you don't need to split with regex, use explode() instead.
  • 4
    @C0D4

    I was using it for regex. Turns out regex engine got changed a bit between 7.2 (my local PHP) and 7.3 (production version). Turns out that life is an endless hell by itself.
  • 3
    @msdsk I was going to come here and ask about this, but seems you figured it out (had this exact same problem before)
  • 1
    @msdsk
    Was it a case of using non-regular patterns? Asking for a friend...
  • 2
    Running different versions of php on local vs production is usually asking for trouble tbh
  • 2
    @Inigo yep preferably never do that on purpose unless you’re gearing up for a php version update for prod.
  • 1
    @Inigo

    Well, I _thought_ I had the same version. Welp, turns out not.
  • 1
    @Oktokolo

    It was [\s-_\/], in 7.3 you need to escape the hyphen.
  • 1
    @msdsk
    Looks regular to me.
    But hyphen embedded in a group actually are to be treated as defining a range if not escaped. So 7.3 fixed a bug.
Add Comment