PHP RegEx: Match the Beginning of the String PHP Script


PHP RegEx: Match the Beginning of the String PHP Script

In previous tutorial we match the given string. Now we are going to match at the beginning of the given string.

 

 
 
  1. <?php
  2. // make a string
  3. $string = 'Ronard';
  4. echo "<b>String: </b>".$string."<br>";
  5. // match the beginning of the string
  6. if(preg_match("/^Ron/", $string))
  7. {
  8. // if it matches we display this line
  9. echo 'The string begins with Ron';
  10. }
  11. else
  12. {
  13. // if no match is found display this line
  14. echo 'No match found';
  15. }
  16. ?>

 

The regex character to read beginning is the caret (^). Then we see if the string given begin with Ron.
The forward slashes (/) we see are the delimeter that hold our regex pattern. And the quotations are used to ‘wrap it all’.
Then we see the (^) will put as the beggining of the string.

 

 


Related Post


Zetta Menu – CSS3 Mega Menu and Drop Down me... Zetta Menu - CSS3 Mega Menu and Drop Down menuZetta Menu - CSS3 Mega Menu and Drop Down menu Zetta Menu is pure CSS3 mega dropdown menu. Mega menu ...
Logaholic Poll and Analytic PHP Script Download Logaholic Poll and Analytic PHP Script Download   Logaholic is a powerful web analytics solution that delivers reliable, objective informatio...
BloodBank – Blood Donor Directory CMS with P... BloodBank is a responsive blood bank and donor Content Management System (CMS). Agents can register and manage donors easily through making a payment ...
Microworkers Clone PHP Script Microworkers Clone PHP Script Free Script Download from horje and many more like plugin module.   Download File  
Scripteen Image Hosting Script_V1.4 PHP Script Dow... Scripteen Image Hosting Script_V1.4 PHP Script Download Nice and user friendly design. High CTR ad placements. Dynamic navigation bar with 3 link...

Have any Question or Comment?

Leave a Reply

Your email address will not be published. Required fields are marked *

"