PHP : Filter String with Array Diff

When you wanted to filter strings through words, you can use array diff to filter known words on string.

Example :

Words = “I want to eat something this morning, but I don’t have any money”

Filter Words = “this”, “but”, “any”

In Php you can use the array diff, first we will separated the words by making it into arrays ..

After the words become array, we then add the filter words into another array and use the array diff to seperate them ..

The value in $textsplit is still in array format, so we use the implode function to stick them together into a string ..

The final coding will look like this ..

The Output will be

Leave a Reply

Your email address will not be published. Required fields are marked *