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. 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 PHP Tutorial 8 min read BasicsPHP Syntax 4 min read PHP Variables 5 min read PHP | Functions 8 min read PHP Loops 4 min read ArrayPHP Arrays 5 min read PHP Associative Arrays 4 min read Multidimensional arrays in PHP 5 min read Sorting Arrays in PHP 4 min read OOPs & InterfacesPHP Classes 2 min read PHP | Constructors and Destructors 5 min read PHP Access Modifiers 4 min read Multiple Inheritance in PHP 4 min read MySQL DatabasePHP | MySQL Database Introduction 4 min read PHP Database connection 2 min read PHP | MySQL ( Creating Database ) 3 min read PHP | MySQL ( Creating Table ) 3 min read PHP AdvancePHP Superglobals 6 min read PHP | Regular Expressions 12 min read PHP Form Handling 4 min read PHP File Handling 4 min read PHP | Uploading File 3 min read PHP Cookies 9 min read PHP | Sessions 7 min read Like