PHP RegEx: Match a pattern at the end of the string PHP Script


PHP RegEx: Match a pattern at the end of the string PHP Script

In previous tutorial we have a pattern that match a string at the beggining using caret(^).
Now we try to match the pattern at the end of the string using \z.

What is \z? This is end of subject or read at the end of subject.
We still use (i) case insensitive modifier so that it can read any case.

 

 
 
  1. <?php
  2. // create a string
  3. $string = 'Ronard';
  4. //display the string Ronard
  5. echo "<b>String is: </b>".$string."<br/>";
  6. // try to match our pattern at the end of the string
  7. if(preg_match("/nard\z/i", $string)) {
  8. // if our pattern matches we echo this
  9. echo 'The string ends with nard';
  10. } else {
  11. // if no match is found we echo this line
  12. echo 'No match found';
  13. }
  14. ?>

 

 

The above script will generate “The string ends with nard” which is read at the end of the subject.

 

 


Related Post


PHPfox v4.5.3 PHP Script Download PHPfox v4.5.3 PHP Script Download This is a popular PHP Script in the world. This script is like Facebook will support Web and Mobile Site, Poll, V...
King MEDIA v3 – Video, Image Upload and Shar... King MEDIA v3 - Video, Image Upload and ShareKing MEDIA v3 - Video, Image Upload and Share Image Upload & Share From Url , Youtube, Facebook, V...
phpFreeChat v2.0.0 Dev PHP Script Download phpFreeChat v2.0.0 Dev PHP Script Download phpFreeChat is a free, simple to install, fast, customizable and multi languages chat that uses a simple...
SVG Donut Charts PHP Script Download SVG Donut ChartsSVG Donut Charts 6 Edge Animate projects (+16 additional examples) with animated SVG Donut Charts for infographics, statistics, das...
Open Journal Systems v2.4.5 PHP Script Download Open Journal Systems v2.4.5 PHP Script Download Open Journal Systems (OJS) is a journal management and publishing system that has been developed by...

Have any Question or Comment?

Leave a Reply

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

"