How to check if a string contains zalgo text?

1.2k Views Asked by At

I'm currently being 'spammed' with zalgo text on my webpage and i need a function to check if it contains zalgo.

I found this code:

if ( preg_match ( '/[^\x20-\x7E]/', $text ) || preg_match ( '/[^\x20-\x7E]/', $text ) ) {
die('ZALGO not allowed');}

but it also blocks some legit posts. Is there a better way?

Thanks

1

There are 1 best solutions below

0
On BEST ANSWER

Zalgo typically falls in the CC and CD unicode ranges. Try matching against /[\xCC\xCD]/. You should generally have a reCAPTCHA anyway to mitigate spam. If it's not 4channers one day then it might be viagra bots the next day.