Skip to content
Advertisement

PHP Only allow specific words in a string [closed]

I’m trying to check if the given string contains words that are not listen in my $allowed array. If it does I want them replaced with “”.

So let’s say my string contains “Hello World” and “World” is not in my allowed words it should replace “World” with “”.

Another issue I have is that my current implementation is case sensitive.

JavaScript

Advertisement

Answer

I can answer partially by showing you how to keep word boundaried words, removing everything else from the string:

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement