What is the purpose of using preg_match() in PHP and what are the potential pitfalls associated with passing parameters to this function?

The purpose of using preg_match() in PHP is to perform a regular expression match on a string. Potential pitfalls associated with passing parameters to this function include incorrectly formatted regular expressions leading to unexpected results, inefficient regular expressions causing performance issues, and not properly handling the return values leading to errors in the code.

// Example of using preg_match() to check if a string contains only letters and numbers
$string = "Hello123";
if (preg_match("/^[a-zA-Z0-9]*$/", $string)) {
    echo "String contains only letters and numbers.";
} else {
    echo "String contains other characters.";
}