What is the purpose of the preg_match function in PHP?

The preg_match function in PHP is used to perform a regular expression match on a string. It is commonly used to check if a specific pattern exists in a string. This function returns true if the pattern is found in the string, and false otherwise.

$string = "Hello World";
$pattern = "/Hello/";

if (preg_match($pattern, $string)) {
    echo "Pattern found in the string.";
} else {
    echo "Pattern not found in the string.";
}