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.";
}
Related Questions
- What are some alternative approaches to achieving the desired effect of stopping autoslide in a Bootstrap Carousel in mobile view?
- What are the potential pitfalls of using IP addresses as the sole method of identifying banned computers in online games using PHP?
- What best practices should be followed when using placeholder attributes in HTML input fields within PHP code?