3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $badwords = array('dog', 'dala', 'bad3', 'ass'); $text = 'This is a dog. . Grass. is good but ass is bad.'; print_r( filterBadwords($text,$badwords)); function filterBadwords($text, array $badwords, $replaceChar = '*') { //$match_found = 0; $repu = preg_replace_callback(array_map(function($w) { return '/\b' . preg_quote($w, '/') . '\b/i'; }, $badwords), function($match) use ($replaceChar) { $match_found = 1; return str_repeat($replaceChar, strlen($match[0])); }, $text ); if(strcasecmp($repu,$text) === 0) echo "ok"; else echo "not ok"; return array('error' =>$match_found, 'text' => $repu ); }
based on MNV4I
Output for 5.6.0 - 5.6.30, hhvm-3.18.5 - 3.21.3, 7.0.0 - 7.3.0beta1
not ok Notice: Undefined variable: match_found in /in/1P1PY on line 20 Array ( [error] => [text] => This is a ***. . Grass. is good but *** is bad. )
Output for hhvm-3.22.0
not ok Notice: Undefined variable: match_found in /in/1P1PY on line -1 Array ( [error] => [text] => This is a ***. . Grass. is good but *** is bad. )