php - Regex check for words and words with spaces separating letters -


so have array of profanities checking in string.

e.g.

$string = 'naughty string'; $words = [     'naughty',     'example',     'words' ]; $pattern = '/('.join($words, '|').')/i'; preg_match_all($pattern, $string, $matches); $matched = implode(', ', $matches[0]); 

but want check profanities split spaces:

e.g.

n u g h t y

yes can adding array:

$words = [     'naughty',     'n u g h t y',     'example',     'e x m p l e',     'words',     'w o r d s' ]; 

but have huge array of "bad" words , wondering if there easy way of doing this?

------ edit ------

so isn't meant super accurate. application every space new line.. string this: n u g h t y string result in this:

n

a

u

g

h

t

y

string

to answer question asked, create pattern b\s*a\s*d instead of bad:

$string = 'some bad , b d , more ugly , u g l y words';  $words = [     'bad',     'ugly' ];  $pattern = '/\b(' . join(     array_map(function($w) {         return join(str_split($w), '\s*');     }, $words), '|') .'\b)/i';  print preg_replace($pattern, '***', $string);  // *** , *** , more *** , *** words 

on more general note, can't reliably remove profanities, in unicode world. there's no way can filter out ƒⓤçκ.


Comments

Popular posts from this blog

how to do line continuation in perl debugger for entering raw multi-line text (EOT)? -

javascript - Create websocket without connecting -

android - Linear layout children not scrolling -