Detecting special characters PHP

后端 未结 2 729
旧巷少年郎
旧巷少年郎 2021-01-25 16:28

I am trying to check whether a string contains any special chars so I know what to do with it afterwards in my script.

Heres what I have:

if (preg_match(         


        
2条回答
  •  有刺的猬
    2021-01-25 16:50

    You forgot some escapes:

    if (preg_match('/[^A-Z0-9_@£\$¥èéùìòÇØø\+%&\!"#'\(\)\*,
                   ^-start string                  ^---end string
    

    Since that's a '-quoted string for the pattern as a whole, all ' inside the pattern MUST be escaped.

提交回复
热议问题