phpblockspamzalgo

How to check if a string contains zalgo text?


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


Solution

  • 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.