How does preg_match() function work in PHP?

The preg_match() function in PHP is used to perform a regular expression match on a string. It returns true if a match is found, and false otherwise. To use preg_match(), you need to provide a regular expression pattern and the string to search within as parameters.

$string = "Hello, World!";
$pattern = "/Hello/";
if (preg_match($pattern, $string)) {
    echo "Match found!";
} else {
    echo "No match found.";
}