Profanity icon indicating copy to clipboard operation
Profanity copied to clipboard

Inserting Persian And Arabic dictionary and Getting the badwords

Open vahid-vahid opened this issue 8 years ago • 5 comments

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 avatar Jun 05 '17 08:06 vahid-vahid

@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(); }

vahid-vahid avatar Jun 05 '17 10:06 vahid-vahid

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 ^^

ConsoleTVs avatar Jun 05 '17 12:06 ConsoleTVs

Yes it works

vahid-vahid avatar Jun 05 '17 13:06 vahid-vahid

The only change I made is what i mentioned before

vahid-vahid avatar Jun 05 '17 13:06 vahid-vahid

Feel free to make a pull request :p

ConsoleTVs avatar Jun 05 '17 14:06 ConsoleTVs