Implementing Conditional and Regular expressions in php

0
1917
Regular expressions

In this tutorial we will learn to implement the conditional as well as regular expressions in php.

  • To study the implementation of conditional and regular expression in php follow the steps given below :

  1. CONDITIONAL EXPRESSION
    1. Install Xampp server in your machine and if it is already installed then go to Xampp-> htdocs folder .
    2. Create a new folder say s6 in this htdocs folder.
    3. v1

    4. In this s6 folder create a new file say index.php and open it with notepad++.
    5. v2

    6. Now write the given code in index.php file :
    7. So you will have the following look out of your notepad++ window :
    8. 1
      2
      3
      4

    9. Now start the required modules i.e the Apache and MySql module from the Xampp control pannel .
    10. Now open up the browser and enter the url as http://localhost/s6/index.php
    11. Hence you will have the following output .
    12. v6

  2. REGULAR EXPRESSION
    1. Now in the same s6 folder create a new file say pregmatch.php and open it with notepad++ .
    2. Now write the following code in it which deals with matching a string :
    3. So you will have the following view of your notepad++ window :
    4. v7

    5. Now open up the browser and enter the given url to run your program http://localhost/s6/pregmatch.php
    6. You will have the following output :
    7. v8

      Note :- if(preg_match(“/ell/”,”Hellow World”,$matches))
      in this condition “/ell/” is used as the find means that is to be found in “Hellow World ” .

      Note:- In this condition
      if(preg_match(“/^ell/”,”ellow World”,$matches))
      ^(caret) symbol represents the beginning string that is starting from “ell” word .If this condition is satisfied then it will display the message Match is found, otherwise it does not display anything in the browser window.

  3. Thus we had a brief study about the conditional and regular expressions in php .

LEAVE A REPLY

Please enter your comment!
Please enter your name here