Source Code:
(back to article)
<?php // $text is a string variable $text = "Hello World!"; // Using the preg_match() function to check if "World" exists in $text if (preg_match('/World/', $text)) { // If preg_match() returns a value other than 0, it means "World" is found in $text echo "Found 'World' in '$text'"; } else { // If preg_match() returns 0, it means "World" is not found in $text echo "Could not find 'World' in '$text'"; }
Result:
Report an issue