PHP: How To Check if String Contains Specific Word or Substring

January 13, 2019

If You are Learning PHP and want to find out How to Work with String in PHP. This Tutorial is For You.

In This Tutorial We are Learning How to Check if String Contains Specific Word or Substring in PHP and also Learn How to Check if a String Contains a Specific Word or Sub string in PHP.

The String Comparsion can be easily done by the PHP built in Function called strpos(). The strpos() function is the easiest way to check if a string contains a specific word or sub string in PHP.

Word in String

The Following Example is Checks Whether a Specific Word exists in the string or not.

In This Example the Word ‘KTechBlog’ found in String. Means Condition is true and print a message.

Substring in String

The Following Example is Checks Whether a Specific Substring exists in the String or Not.

In This Example the Substring ‘the Learning’ found in String. Means Condition is true and print a message.

The strpos() function is case-sensitive. use the stripos() function for case-sensitive comparison in PHP.

Hope This Help…….!!!

Leave a Reply

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