Range out of order in character class

前端 未结 7 1586
广开言路
广开言路 2020-12-07 00:20

I\'m getting this odd error in the preg_match() function:

Warning: preg_match(): Compilation failed: range out of order in character class at offset 54

The l

7条回答
  •  被撕碎了的回忆
    2020-12-07 01:02

    While the other answers are correct, I'm surprised to see that no-one has suggested escaping the variable with preg_quote() before using it in a regex. So if you're looking to match an actual bracket or anything else that means something in regex, that'll be converted to a literal token:

    $escaped = preg_quote($gsmNumber);
    preg_match( '/(.*)/s', $fileData, $matches);
    

提交回复
热议问题