Page 325 - Computer Software Application TP - Volume 1
P. 325

COMPUTER SOFTWARE APPLICATION - CITS




                             <html >
                    <head>
                         <title> Using preg_quote() </title>

                    </head>
                    <body>
                           <?php
                 // String containing characters to be quoted

                 $string = “Escaping: .\+*?[^]{}()$=!|:-”;
                 // Quote the string to escape regular expression characters
                 $quotedString = preg_quote($string);
                 // Regular expression pattern containing the quoted string
                 $pattern = ‘/^’ . $quotedString . ‘$/’;
                 // Test string to match against the pattern
                 $testString = “Escaping: .\\+*?[^]{}()$=!|:-”;
                 // Perform regular expression matching
                 if (preg_match($pattern, $testString)) {
                         echo “String matches the pattern.\n”;

                 } else {
                         echo “String does not match the pattern.\n”;
                 }
                 ?>

                 </body>
                    </html>
              3  Save the program in C:\Apache24\htdocs in a folder with .php extension
              4  Run the Apache services from windows services
              5  Open the browser and type the following address
                 http://localhost/foldername/
              6  Click the php file to run and verify the output
           1  Provide an example of using a regular expression to match a single character in PHP
           2  Provide an example of a regular expression pattern in PHP that matches any digits 0 to 9?
           3  Provide an example of exclude specific characters from a set when using a regular expression in PHP?
           4  Provide an example of a regular expression in PHP that matches exactly three occurrences of a specific
              pattern?
           5  provide an example of a regular expression in PHP that matches a word boundary at the beginning of a word?
           6  Give an example of a situation where using the (case-insensitive) modifier in PHP regular expressions?
           7  Provide an example of a complex regular expression pattern where using the (extended) modifier in PHP
              would enhance readability.
           8  Provide an example of the (extended) modifier changes the behavior of whitespace and comments within a
              regular expression pattern.
           9  Provide an example of how to use preg_match_all() in PHP to extract multiple occurrences of a pattern from
              a string?
           10 Provide an example of preg_split() handle capturing groups within the regular expression pattern when splitting
              a string in PHP
           11 Give a sample PHP code of using regular expressions for email validation?




                                                           310

                               CITS : IT & ITES - Computer Software Application - Exercise 58
   320   321   322   323   324   325   326   327   328   329   330