- preg_match: documentation ( source)
- var_export: documentation ( source)
- implode: documentation ( source)
- explode: documentation ( source)
- preg_quote: documentation ( source)
<?php
$input = [
"Lincoln Crown",
"Crown Court",
"go holiday",
"house fire",
"John Hinton",
"Hinton Jailed"
];
$output = [];
$blacklist = [];
foreach ($input as $string) {
if (!$blacklist || !preg_match('/\b(?:' . implode('|', $blacklist) . ')\b/', $string)) {
$output[] = $string;
}
foreach(explode(' ', $string) as $word) {
$blacklist[$word] = preg_quote($word);
}
}
var_export($blacklist);
echo "\n";
var_export($output);