Nolongerused3921 Posted March 5, 2006 Share Posted March 5, 2006 Well, its my first time using regex and I'm having a bit of a problem: I need to split the following string:[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]a:6:{s:12:"firstinsertd";s:10:"01-01-1970";s:12:"firstinsertt";s:8:"01:00 AM";s:7:"updated";s:10:"10-13-2005";s:7:"updatet";s:8:"05:37 PM";s:6:"amount";d:51218.2087766306431149132549762725830078125;s:10:"updatetime";i:1131550652;}[/quote]So I can get the amount (512218) alone, without the decimal, or ;d:... But I just can't figure out how to do it.Heres my regex, which seems to return the number AFTER the decimal as [1] in the array (Along with ";s:10:"updatetime";i:1131550652;} )", for some reason) :[code]$ucashbank = 'a:6:{s:12:"firstinsertd";s:10:"01-01-1970";s:12:"firstinsertt";s:8:"01:00 AM";s:7:"updated";s:10:"10-13-2005";s:7:"updatet";s:8:"05:37 PM";s:6:"amount";d:51218.2087766306431149132549762725830078125;s:10:"updatetime";i:1131550652;}';$test = preg_split("/amount\";[d]:([0-9])*[.]/", $ucashbank);print_r($test);[/code]Returns:[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Array ( [0] => a:6:{s:12:"firstinsertd";s:10:"01-01-1970";s:12:"firstinsertt";s:8:"01:00 AM";s:7:"updated";s:10:"10-13-2005";s:7:"updatet";s:8:"05:37 PM";s:6:" [1] => 2087766306431149132549762725830078125;s:10:"updatetime";i:1131550652;} )[/quote]Anyone know what I'm doing wrong? Quote Link to comment Share on other sites More sharing options...
JasperBosch Posted March 5, 2006 Share Posted March 5, 2006 Hi Sykoi,I think you try the wrong way. Why use regular expression?Why not use unserialize?I should do it this way:[code]$var = unserialize($ucashbank);$amount = ceil($var['amount']);[/code]This wil return the result you disire. Quote Link to comment Share on other sites More sharing options...
Nolongerused3921 Posted March 5, 2006 Author Share Posted March 5, 2006 Wow that worked very well, thanks :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.