dimanche 12 novembre 2017

Laravel 5.5 - Check if string contains exact words

In laravel, I have a $string and a $blacklistArray

$string = 'Cassandra is a clean word so it should pass the check';
$blacklistArray = ['ass','ball sack'];

$contains = str_contains($string, $blacklistArray); // true, contains bad word

The result of $contains is true, so this will be flagged as containing a black list word (which is not correct). This is because the name below partially contains ass

Cassandra

However, this is a partial match and Cassandra is not a bad word, so it should not be flagged. Only if a word in the string is an exact match, should it be flagged.

Any idea how to accomplish this?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2mjQhci
via IFTTT

Aucun commentaire:

Enregistrer un commentaire