Welcome to FindNerd. Today we are going to discuss the pattern making for regular expersions in php. We use the inbuild functions named preg_match and preg_match_all
to find the matching one from the string. Before starting using this functions you need to undertand the rules for pattern making. PHP use the perl compatible Regular
expression(PCRE) syntax fpr regular expressions.Please check an small example.
<?php
$web_url = 'http://www.google.com';
echo $total_one = preg_match('#http\/\/#',$web_url);
?>
result : 1
In above example we can see the function preg_match which will return 1 because it found http:// substring only one time. If there is no match then it will return
0. preg_match function will stop when first match is found. If one sub string found multiple time in string then you need to use the preg_match_all function. We
will discuss it next blog. When we make the pattern then we enclose it in delimiters. Delimiters are non-alphanumeric, non-backslash and non-whitespace characters
like / string / , # string # , % string % etc
0 Comment(s)