PHP : Extract values using RegEx


My daily cup of tea

Extracting values from a pattern of string is fairly simple in PHP. I use RegEx to do that often:

e.g. I am trying to extract the numerical value from this expression ” + 15 days “;

$lic_Expiry = " +15 days";
$pattern = "/\s*\+(.*)/";
if(preg_match($pattern, $lic_Expiry, $matches))
echo "$matches[1]\n";

Note: If there are multiple elements that you would like to extract from the expression – use multiple round braces (Your-Regex) and the value will be passed on to the array $matches.

View original post

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s