String matches: string start
<?php
$pattern = "/^PHP$/";
$string = " PHP ";
if(preg_match($pattern, $string)){
print("Found a match!");
}
$string = "PHP is ";
if(preg_match($pattern, $string)){
print("This line won't print!");
}
?>
Related examples in the same category