Re: RIGHT Function?

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

 



Jim,

$parts = explode(PHP_EOL, $item['unitprice']);

$price = '$'.(( count($parts) > 1 ) ? $parts[0] : $parts[(count($parts)-1)]);

For some reason, I couldn't get explode to work with PHP_EOL. $parts[0] would return the entire field, so apparently it wasn't "exploding". So I tried exploding on the ')' instead, which worked, but the return character that's after the ')' was included in the output, i.e.:
$
6.56

so I added 'trim' which took care of that. I also had to use 'number_format' again, since there are exact dollar amounts like 413. Here's what ended up working for me:

$parts = explode(')', $item['unitprice']);
$price = '$'.number_format(trim((( count($parts) > 1 ) ? $parts[(count($parts)-1)] : $parts[0])),2);


Any idea why PHP_EOL didn't work? If I could get it to work, I could remove the trim function and 2 of those parentheses, which would look a lot nicer.

Thanks again,
Frank

--
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