Re: RIGHT Function?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



----- Original Message ----
> From: Tommy Pham <tommyhp2@xxxxxxxxx>
> To: PHP General List <php-general@xxxxxxxxxxxxx>
> Sent: Thursday, September 24, 2009 12:19:51 PM
> Subject: Re:  RIGHT Function?
> 
> ----- Original Message ----
> > From: Jay Blanchard 
> > To: sono-io@xxxxxxxxxxxxx; PHP General List 
> > Sent: Thursday, September 24, 2009 12:15:13 PM
> > Subject: RE:  RIGHT Function?
> > 
> > [snip]
> > I have a price field that sometimes contains entries like this:
> > 
> > 250,(min)
> > 5.32
> > 
> >     How can I pull just the price ($5.32 in this example) from this
> > field  
> > to display on a web page?  Is there a RIGHT function in PHP?  When I  
> > search the PHP site, I'm being told there isn't one.
> > 
> >     Here's the code I've been using:
> > [/snip]
> > 
> > substr will work from right to left.
> > 
> > If your data is in a variable do this;
> > 
> > echo substr($myData, -5);
> > 
> > Why -5? To account for 2 decimal places, the decimal and up to 99
> > dollars?
> > 
> > http://www.php.net/substr
> > 
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> 
> http://dev.mysql.com/doc/refman/5.1/en/string-functions.html

If you want to retain the ',(min)' for other uses, you'll have to do it in PHP

http://www.php.net/manual/en/ref.strings.php

stripos() and substr() will do it if you don't want to deal with/learn regex


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux