String matches: string start : String Matches « String « PHP






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

1.String match for domain name
2.A simple use of preg_match()
3.String matches: ^ (begine)
4.String match demo: /[cd][oa][gt]/
5.String match demo: |
6.$: anchors a pattern to the end of a line or the end of the string
7.String match and if statement