Warning: preg_replace() [function.preg-replace]: Compilation failed: nothing to repeat at offset 1

前端 未结 1 477
独厮守ぢ
独厮守ぢ 2021-01-13 02:40

Can someone help debug this error?

Warning: preg_replace() [function.preg-replace]: Compilation failed: nothing to repeat at offset 1

1条回答
  •  再見小時候
    2021-01-13 02:44

    * in regex means to match the previous character 0 or more times, while ( starts a capturing group. So, the * has nothing to repeat, since what comes before the * is a (, which cannot be repeated by itself, hence this warning.

    To fix it, just escape the *, like so:

    $uid = preg_replace("#(\*UTF8)[^A-Za-z0-9]#", "", $tmp);
    

    0 讨论(0)
提交回复
热议问题