In the following code why the PHP preg_match returns false?
note: I have read some older questions with the same title as my question but the context was different
<html>
<head>
</head>
<body>
<?php
$str = "This is a test for PCRE.";
$ptrn = "This";
$preg_match_result_arr;
$preg_match_result = preg_match($ptrn, $str, $preg_match_result_arr);
if (1 === $preg_match_result)
{
echo "The pattern has matched in the string:<br/>".
"the match is $preg_match_result_arr[0]<br/>";
}
elseif (0 === $preg_match_result)
{
echo "The pattern has not matched in the string:<br/>";
}
elseif (false === $preg_match_result)
{
echo "An error has occured in matching<br/>";
}
?>
</body>
</html>
You are missing the delimiters, your pattern should look like (
#used but it can be something else):