Google Ads

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

Max’s Calendar PHP Script Max's Calendar PHP Script Calendar viewer, easy to use. Installation: Copy the downloaded files to your storage, index.php displays the calen...
FTP – Droppy online file sharing v1.0.1 PHP ... FTP - Droppy online file sharing v1.0.1FTP - Droppy online file sharing v1.0.1The FTP Plugin for Droppy – Online file sharing connects your existing...
WhizClassified v1.7 – Classifieds CMS PHP Sc... WhizClassified v1.7 - Classifieds CMSWhizClassified v1.7 - Classifieds CMSWhizClassified : Complete and easily manageable Classifieds CMSDemo: http://...
Phoenix v1.4 – modern & minimalist news... Phoenix v1.4 - modern & minimalist news portalPhoenix v1.4 - modern & minimalist news portalPhoenix is a modern news portal. It contains an extremely ...
PHP RegEx: Meta Character class PHP Script PHP RegEx: Meta Character class PHP Script We already seen the caret(^) as match the the beginning of string and (z) match at the end of string th...

Have any Question or Comment?

Leave a Reply

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

"