How to trim words?

I'm trying to cut words in the text but, the function truncates full words:

$text = 'like politics and business influence news ';
$text = str_replace(
 array('as', 'no', 'from', 'c', 'in', 'for', 'a', 'and'),
 array(", ", ", ", ", ", ", "),
$text
 );


Trims:

business => bnes,
news => Noot,
politics = > Polska

It should be : politics business influence news
April 3rd 20 at 17:36
1 answer
April 3rd 20 at 17:38
Solution
Good morning.
Bit different to do.
$text = 'like politics and business influence news ';

$array = ['as', 'no', 'from', 'c', 'in', 'for', 'a', 'and'];

$words = explode(' ', $text);

// politics business influence news 
echo implode(' ', array_diff($words, $array));
Thank you - Jaylen73 commented on April 3rd 20 at 17:41
@Leonardo, please. - lonnie22 commented on April 3rd 20 at 17:44

Find more questions by tags PHP