What is the purpose of using preg_match in PHP and what are some common issues that may arise when using it?

When using preg_match in PHP, a common issue that may arise is not properly escaping special characters in the regular expression pattern. This can lead to unexpected results or errors when trying to match a specific string. To solve this issue, it is important to use the preg_quote function to escape special characters before constructing the regular expression pattern.

$pattern = '/^' . preg_quote($search_string, '/') . '$/';
if (preg_match($pattern, $input_string)) {
    echo "String matched!";
} else {
    echo "String not matched!";
}