PHP RegEx: Match A String PHP Script


PHP RegEx: Match A String PHP Script

In this tutorial I will show you the basic in regex.

In brief discussion.

Regex is considered a method of matching pattern within a string. In PHP usually used PCRE or “Perl Compatible Regular Expressions”.

Let’s see a sample to print a string.

 

 
 
  1. <?php
  2. // create a string
  3. $string = 'abcdefghijklmnopqrstuvwxyz0123456789';
  4. // echo our string
  5. echo $string;
  6. ?>

 

The above code are printing “abcdefghijklmnopqrstuvwxyz0123456789”. Now were going to match the character “xyz” using regex.

 

 
 
  1. <?php
  2. // create a string
  3. $string = 'abcdefghijklmnopqrstuvwxyz0123456789';
  4. echo preg_match("/xyz/", $string);
  5. ?>

 

 

The code above will output “1” because the character “xyz” are matches to the string given. Then the preg_match will output zero “0” if it could not matches to the string given.

 

 


Related Post


Activ’Map Nearby Places v2.0.0 – Respo... The perfect plugin to research and locate custom services and equipments in a city. Activ’Map is a jQuery plugin using the Google Maps API V3 and Boot...
CronLab PTC v2.2 – All in One Script for PTC... CronLab PTC | All in One Script for PTC, HyIp, Crypto Trade & Money Investment which allows you to earn money in so many different ways. This Scri...
Question2Answer v1.5.3 PHP Script Question2Answer v1.5.3 PHP Script Question2Answer site helps your online community to share knowledge. People with questions quickly get the answer...
MenorahOES v1.1 – Online Learning and Examin... MenorahOES v1.1 - Online Learning and Examination SystemMenorahOES v1.1 - Online Learning and Examination System MenorahOES – The IBPS clone an O...
Easy Video Background PHP Script Download Easy Video BackgroundEasy Video Background Easy Video Background lets you add video in the background of your website with a single javascript call...

Have any Question or Comment?

Leave a Reply

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

"