Re: RIGHT Function?
| From: | sono-io at fannullone dot us | Date: | Sat, 14 Nov 2009 00:58:44 +0000 |
| Subject: | Re: RIGHT Function? | ||
| References: | 1 2 3 4 5 6 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-299820@lists.php.net to get a copy of this message | ||
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