How to check if a string contains another string in PHP

Learn how to find out if a given string is in a different string in PHP in this quick and easy tutorial.

First, let’s define the two strings as follows:

$string = "this is a sample string!"
$search_term = "ring"

To find out if $string contains $search_term, perform the following:

if (strstr($search_term, $string))
	// search term was found

That’s all there is to it!

Love our articles? HostM offers professional and helpful web hosting services with unlimited features and renewal rates that actually match our advertised rates.