PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Thu Aug 22, 2019 3:18 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: Simple Question...
PostPosted: Fri Sep 03, 2004 6:45 pm 
Offline
Forum Regular
User avatar

Joined: Sun Feb 29, 2004 2:26 pm
Posts: 939
Location: UK - Glasgow


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 03, 2004 6:52 pm 
Offline
Neighborhood Spidermoddy
User avatar

Joined: Mon Mar 29, 2004 4:24 pm
Posts: 31559
Location: Bothell, Washington, USA


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 03, 2004 6:56 pm 
Offline
Forum Regular
User avatar

Joined: Sun Feb 29, 2004 2:26 pm
Posts: 939
Location: UK - Glasgow
Hmm would that be like:

Syntax: [ Download ] [ Hide ]
$alter = preg_match("#£(\d*)(\.(\d*))?[^.\d]#", $order->info['total']);


It does not seem to work, All I get is 0...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 03, 2004 7:23 pm 
Offline
Forum Regular
User avatar

Joined: Sun Feb 29, 2004 2:26 pm
Posts: 939
Location: UK - Glasgow
Oh and sorry I forgot to mention, the price actually shows like:

51.32

So would your (feyd's) expression turn out like:

Syntax: [ Download ] [ Hide ]
$alter = preg_match("#(\d*)(\.(\d*))?[^.\d]#", $order->info['total']);


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 03, 2004 7:26 pm 
Offline
Neighborhood Spidermoddy
User avatar

Joined: Mon Mar 29, 2004 4:24 pm
Posts: 31559
Location: Bothell, Washington, USA


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 03, 2004 7:36 pm 
Offline
Forum Regular
User avatar

Joined: Sun Feb 29, 2004 2:26 pm
Posts: 939
Location: UK - Glasgow


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 03, 2004 8:12 pm 
Offline
Neighborhood Spidermoddy
User avatar

Joined: Mon Mar 29, 2004 4:24 pm
Posts: 31559
Location: Bothell, Washington, USA


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 03, 2004 8:32 pm 
Offline
Forum Regular
User avatar

Joined: Sun Feb 29, 2004 2:26 pm
Posts: 939
Location: UK - Glasgow
Yeah its ok I got it, thanks. I was wondering though, when you said use the third argument to get the matches do you mean like:

Syntax: [ Download ] [ Hide ]
$alter = preg_match("#£(\d*)(\.(\d*))?[^.\d]?#", $order->info['total'], matches[0]);


Regular expressions is something I STILL need to catch up on, heh.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 03, 2004 8:44 pm 
Offline
Neighborhood Spidermoddy
User avatar

Joined: Mon Mar 29, 2004 4:24 pm
Posts: 31559
Location: Bothell, Washington, USA
read the doc page: [php_man]preg_match[/php_man]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 03, 2004 9:33 pm 
Offline
PHP Evangelist
User avatar

Joined: Tue Aug 13, 2002 3:35 pm
Posts: 3547
Location: Calgary, Canada
And the non-regex way

Syntax: [ Download ] [ Hide ]
$price = 19.99;

$parts = explode (".", $price);

$dollars = (int) $parts[0];

$cents = (int) $parts[1];


If the variable had $, or another symbol in it, a simple [php_man]str_replace[/php_man]() would solve that problem. :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 03, 2004 9:53 pm 
Offline
DevNet Master

Joined: Tue Jan 20, 2004 12:11 am
Posts: 4897
Location: Leuven, Belgium
Generally i don't like regular expressions because of their performance hit...
Well, after a thread on comp.lang.php

i changed my mind ;)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 03, 2004 10:02 pm 
Offline
Forum Newbie

Joined: Wed Sep 01, 2004 1:08 am
Posts: 14
this will work too...
$price = 19.99;
$cent = substr($price, -2); // returns "99"


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Majestic-12 [Bot] and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group