How to check if a String Contains a Substring in PHP ? Last Updated : 23 Jul, 2025 Comments Improve Suggest changes 1 Likes Like Report Checking whether a string contains a specific substring is a common task in PHP. Whether you're parsing user input, filtering content, or building search functionality, substring checking plays a crucial role.MethodsBelow are the following methods by which we can check if a string contains a substring in PHP:1. Using str_contains() (PHP 8+) PHP <?php $text = "Welcome to Empowerfit!"; if (str_contains($text, "Empower")) { echo "Substring found!"; } else { echo "Substring not found."; } ?> Output:Substring found!2. Using strpos() (All PHP versions) PHP <?php $text = "Learn PHP programming"; if (strpos($text, "PHP") !== false) { echo "Substring found!"; } else { echo "Substring not found."; } ?> Output:Substring found!3. Case-Insensitive Search with stripos() PHP <?php $text = "Power of Coding"; if (stripos($text, "power") !== false) { echo "Substring found (case-insensitive)!"; } ?> Output:Substring found (case-insensitive)!4. Using Regular Expressions with preg_match() PHP <?php $text = "Develop with PHP"; if (preg_match("/PHP/", $text)) { echo "Match found using regex."; } ?> Best PracticesUse str_contains() for simple checks (if PHP 8+).Always check strpos with !== false, not != false.Use stripos() for case-insensitive searches.Prefer preg_match() only for complex pattern matching. Create Quiz Comment S sravankumar_171fa07058 Follow 1 Improve S sravankumar_171fa07058 Follow 1 Improve Article Tags : Web Technologies PHP PHP-string PHP-function PHP-Questions +1 More Explore BasicsPHP Syntax4 min readPHP Variables5 min readPHP | Functions6 min readPHP Loops4 min readArrayPHP Arrays5 min readPHP Associative Arrays4 min readMultidimensional arrays in PHP5 min readSorting Arrays in PHP4 min readOOPs & InterfacesPHP Classes2 min readPHP | Constructors and Destructors5 min readPHP Access Modifiers4 min readMultiple Inheritance in PHP4 min readMySQL DatabasePHP | MySQL Database Introduction4 min readPHP Database connection2 min readPHP | MySQL ( Creating Database )3 min readPHP | MySQL ( Creating Table )3 min readPHP AdvancePHP Superglobals6 min readPHP | Regular Expressions12 min readPHP Form Handling4 min readPHP File Handling4 min readPHP | Uploading File3 min readPHP Cookies9 min readPHP | Sessions7 min read Like