Home of web learners

www.webn3rd.com

PHP has regular expression to make a search in string

Lets start with an example:


          <?php
         $pattern 
"/e/";
$text "webn3rd";
$totalmatch=preg_match_all($pattern$text);
echo 
$totalmatch;
?>

Here,you see that,we have two things,first test is for which we are searching for and next text where we are searching.

Here,in preg_match_all we use this to find all matches character in our text,in this example we find only one e,so outpur is 1

webn3rd.com

About webn3rd