Like Us Like Us Facebook Subscribe Subscribe us YouTube Whatsapp Share us Whatsapp Query Send your queries

Learn PHP Preg_match with working Example

Learn PHP Preg_match with working Example

preg_match is a wonder ful function of PHP( 4,5,6) to Perform a regular expression match. Its little bit difficult to learn but extremely useful when you properly understand it. Extensively use to extract string in SEO process, in validation of E-mail ID and so its impossible for me to describe its utilization in PHP Development.
Structure :
( string $pattern
, string $subject
[, array &$matches
[, int $flags = 0
[, int $offset = 0
]]] )
Simplified Version
preg_match(pattern, Subject ,array)
Pattern-  The pattern to search for, as a string.
Subject = Variable that contains that value
Array-  to store extracted value.
For more details visit
A Simple Example:
This example extract title from title tags, heavily used is SEO industry.
$sanjay='<title>Please share this page to twitter, Google Plus and Twitter</title>’;
echo $mt[‘1’];
Note : use / to start a pattern and /i to end. Use (.*) to find the desired value.
Above Code will give a out put
Please share this page to twitter, Google Plus and Twitter

6 Comment

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Do you have any Query / Suggestion