ConsoleTVs / Profanity

PHP library to block bad words in a string
MIT License
98 stars 46 forks source link

Inserting Persian And Arabic dictionary and Getting the badwords #2

Open vahid-vahid opened 7 years ago

vahid-vahid commented 7 years ago

Hi again I want to insert an array of Persian and Arabic dictionary array and get the badwords

The text cleanness is discovered correctly but the badwords function returns unknown characters

$bad = Profanity::blocker('فحش است')->dictionary([['language' => 'fa' , 'word' => 'فحش' ]])->badWords();

returns array (size=1) 0 => array (size=2) 'language' => string 'fa' (length=2) 'word' => string '������' (length=6)

Please help me with this problem Thank you

vahid-vahid commented 7 years ago

@ConsoleTVs This is The Way I solved it The problem was strtolower does not work on MultiByte characters So I used the method mb_stripos(and is_Numeric to find if it returned something other than false):

public function badWords() { return collect($this->dictionary)->filter(function ($value) { return is_numeric(mb_stripos($this->text, $value['word'])); })->map(function ($value) { return [ 'language' => $value['language'], 'word' => $value['word'], ]; })->toArray(); }

ConsoleTVs commented 7 years ago

Hello @v01061374 Does this solution work with other languages?

If so, I would recommend you to make a pull request, so we can all benefit ^^

vahid-vahid commented 7 years ago

Yes it works

vahid-vahid commented 7 years ago

The only change I made is what i mentioned before

ConsoleTVs commented 7 years ago

Feel free to make a pull request :p