Ask for advice. & Lt ;? Php $ subject & nbsp; abcdef; $ pattern & nbsp; ^ def; preg_match ($ pattern, & nbsp; $ subject, & nbsp; $ matches ); print_r ($ matches );? & Gt; Why cannot I output anything? Ask for advice.
$subject = "abcdef";
$pattern = '/^def/';
preg_match($pattern, $subject, $matches);
print_r($matches);
?>
Why cannot I output anything?
Share:
------ Solution --------------------
^ Indicates the start of the string, but the start of the string is abc rather than def, so it cannot be matched.
------ Solution --------------------
Because the regular expression does not match, if you want to find the final one, it should be/def $/, so there should be output.
------ Solution --------------------
Reference:
$subject = "abcdef";
$pattern = '/^def/';
preg_match($pattern, $subject, $matches);
print_r($matches);
?>
Why cannot I output anything?
This is the simplest problem. The meaning of the special characters in a regular expression is not very clear. it is recommended that you take the time to learn the regular expression.