I want to remove some words from a string:
String:
fa fa-word livicon fa-word-small fantastic
Output should be
fantastic
You want to use preg_replace()
with a regular expression that uses word boundaries and an optional grouping for the -word-etc
parts of your prefixed strings. The below would suffice ...
$str = 'fa fa-word livicon fa-word-small fantastic';
$str = preg_replace('~\b(?:fa(?:-\w+)*|livicon)\b~', '', $str);
echo trim($str); //=> "fantastic"