Jump to content

Archived

This topic is now archived and is closed to further replies.

Nolongerused3921

Problem with a regex

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.