Friday, 30 August 2013

Find date after a particular word

Find date after a particular word

I would like to find the date in a string after a particular word (key).
My string is dynamic and the date format also not same from one string to
another string.
$data = "Balance- 0.30,Val-Aug 29 2013, Free Bal- 0.00";
or
$data = "Bal: 96.27.Valid Sep 26 2013.Toll Free Dial 578785";
or
$data = "BalanceRs.0.00,Expiry date: Apr 04 20141 Live Scores";
or
$data = "Your current balance is 0.20.Your account expires on 2013-11-23
23:59:59.";
or
$data = "Main Bal Rs.87.850 Val 09-07-2014,More";
$key = array('Val-','Val','Valid','Expiry date:','expires on');
$result=preg_match_all("/(?<=(".$key."))(\s\w*)/i",$data,$networkID);
$myanswer = @$networkID[0][0];
Here I am getting the output of only the first word.
Anyone please guide me to get the date. Thanks.

No comments:

Post a Comment