我目前正在创建一个聊天,似乎无法找到一种方法来阻止用户发布特殊字符,这些字符会扰乱聊天的格式并使最终用户退出聊天。
我基本上是想完全删除它们。我知道我现在拥有的代码“从技术上讲,如果它有效”应该只能替换它们,但是我只是想让它首先工作。
这是我用来审查/抓取变量的代码。我认为 htmlentities() 可以做到这一点,但似乎无法正常工作。
$message = $censor->censorString(
$this->parseUrls(
htmlentities(
strip_tags(
$message)
)
)
); //Stripping $message of profanity, html tags, and special characters
Here is a screenshot of my problem:
与您在 StackOverflow 上找到的许多答案相反,它is使用支持 Unicode 类别匹配的正则表达式引擎来清理“Zalgo”文本很简单。 PHP 的preg_*
函数使用 PCRE 库。如果 PCRE 编译为--enable-unicode-properties
,您可以使用以下方法去除所有 Unicode 组合标记:
$sanitized = preg_replace('/\pM/u', '', $zalgo);
或者允许一定数量的连续组合标记,例如:
$sanitized = preg_replace('/(\pM)\pM+/u', '\1', $zalgo);
Or two:
$sanitized = preg_replace('/(\pM{2})\pM+/u', '\1', $zalgo);
这会将 Zalgo 文本变成
T̫̺̳o̬̜ ì̬͎̲̟nv̖̗̻̣̹̕o͖̗̠̜̤k͍͚̹͖̼e̦̗̪͍̪͍ ̬ͅt̕h̠͙̮͕͓e̱̜̗͙̭ ̥͔̫͙̪͍̣͝ḥi ̼̦͈̼vЉ̩̟͚̞͎e͈̟̻͙̦̤-m̷̘̝̱í͚̞̦̳n̝̲̯̙̮͞d̴̺̦͕̫̗̭̘͎͖r̞͎̜̜͖͎̫͢ep͇r̝̯̝̖͉͎ e̴s̥e̵̖̳͉͍̩̗n̢͓̪͕̜̰̠̦t̺̞̰i͟nЉ̮̦̖̟g̮͍̱̻͍̜̳̳c̖̮̙̣̰̠̩h̷̗͍̖͙̭͇͈a̧͎̯̹̲̺ ̫ó̭̞̜̣̯͕s̶̤̮̩̘.̨̻̪̖͔
̳̭̦̭̭̦̞́I̠͍̮n͇̹̪̬v̴͖̭̗̖o̸k̸̬̤͓͚̠͍i͜n̛̩̹͉̘̹g͙ ̠̥ͅt̰͖͞h̫̼̪e̟̩̝ ̭̠̲̫͔fe ̤͇̝̱e͖̮̠̹̭͖͕l͖̲̘͖̠̪i̢̖͎̮̗̯͓̩n̸̰g̙̱̘̗͚̬͍ͅo͍͍̩̮͢f̖͓̦̥̘͘c̵̫̱̗͚͓̦h͝a̝͍ ͍̳̣͖͉o͙̟s̤̞.̙̝̭̣̳̼͟
̢̻͖͓̬̞̰̦W̮̲̝̼̩̝͖i͖͖͡ͅt̘̯͘h̷̬̖̞̙̰̭̳̭̪̕o̥̤̺̝̼̰̯͟ṳ̞̭̤t̨͚̥̗̟̺̫̩̤̳̩ o̟̰̩̖ͅr̞̘̫̩̼d̡͍̬͎̪̺͚͔e͓͖̝̙r̰͖̲̲̻̠.̺̝̺̟͈
̣̭T̪̩̼h̥̫̪͔̀e̫̯͜ ̨N̟ẻ͔̤zp̮̭͈̟é͉͈ṛ̹̜̺̭͕d̺̪̜͇͓i̞á͕̹̣̻n͉͘ ̗͔̭͡h̲͖̣̺̺i͔ ̣̖̤͎̯v̠̯̘͖̭̱̯e̡̥͕-m͖̭̣̬̦͈i͖n̞̩͕̟̼̺͜d̘͉̯o̷͇̹͕̦f̰̱ ̝͓͉̱̪̪c͈̲̜̺h̘͚a̞͔ ̰̯̗̝o̙͍s͍͇̱͓.̵͕̰͙͈ͅ ̯̞͈̞̱̖Z̯̮̺̤̥̪̕a͏̺̗̼̬̗ḻg͢o̥̱̼.̺̜͇͡ͅ ̴͓͖̭̩͎̗
̧̪͈̱̹̳͖͙H̵̰̤̰͕̖e̛ ͚͉̗̼̞w̶̩̥͉̮h̩̺̪̩͘ͅọ͎͉̟ ̜̩͔̦̘ͅW̪̫̩̣̲͔̳a͏͔̳͖i͖͜t͓ ̤̠͓͙s̘̰̩̥̙̝ͅ ̲̠̬̥Be̡̙̫̦h̰̩i̛̫͙͔̭̤̗̲n̳͞d̸͎̻͘T̛͇̝̲̹̠̗ͅh̫̦̝ͅe̩̫͟ ͓͖̼W͕ ͎͚̙̥ą̙l̘͚̺͔͞ͅl̳͍̙̤̤̮̳.̢
̟̺̜̙͉Z̤̲̙̙͎̥̝A͎̣͔̙͘L̥̻̗̳̻̳̳͢G͉̖̯͓̞̩̦O̹̹̺!̙͈͎̞̬ *
变成类似的东西
T̫o̬ ì̬nv̖o͖k͍e̦ ̬t̕h̠e̱ ̥ḥi̼v̉e͈-m̷í͚n̝d̴ ̗r̞ep͇r̝e̴s̥e̵n̢t̺i͟ṋg̮ ̳c̖h̷a̧ó̭s̶.̨ ̳I̠n͇v̴o̸k̉i͜n̛g͙ ̠t̰h̫e̟ ̭fe̤e͖l͖i̢n̸g̙ ͍o͍f̖ ̘c̵h͝a̝o͙s̤.̙ ̢W̮i͖t̘h̷ ̭o̥ṳ̞t̨ ̟o r̞d̡e͓r̰.̺ ̣T̪h̥e̫ ̨N̟eЉzp̮é͉ṛ̹d̺i̞á͕n͉ ̗h̲i͔v̠e̡-m͖i͖n̞d̘ ̯o̷f̰ ̝c͈h̘a̞o̙s͍.̵ ̯Z ̯a͏ḻg͢o̥.̺ ̴ ̧H̵e̛ ͚w̶h̩ọ͎ ̜W̪a͏i͖t͓s̘ ̲Be̡h̰i̛n̳d̸ ͎T̛h̫e̩ ͓W͕ą̙l̘l̳.̢ ̟Z̤A͎L̥G ͉O̹!̙ *
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)