Avatar ·

How to check if a string contains a specific word in PHP?

Hello everyone! I'm a beginner in PHP and writing a small script for processing comments on a website. I need to check if a string contains a specific word, for example, if a user wrote "spam" or "advertisement", the comment should be blocked. \n\nThe problem is that I've tried several methods, but they don't work as I expect. Here's what I've done:\n\n```php\n$text = "This is a great site, thanks!";\nif ($text == "thanks") {\n echo "Found!";\n}\n```\n\nThis code only works if the string is exactly equal to the word "thanks", but if there are other words, the condition is not met. I also tried using `strpos()`, but it doesn't always find the word. For example:\n\n```php\n$text = "Hello, how are you?";\nif (strpos($text, "how")) {\n echo "Found!";\n}\n```\n\nSometimes