note 54473 added to function.trim
| From: | chris dot cowart at gmail dot com | Date: | Tue, 05 Jul 2005 17:20:57 +0000 |
| Subject: | note 54473 added to function.trim | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-91480@lists.php.net to get a copy of this message | ||
Here's a neat function to trim off extraneous zeros and the decimal, leaving important numbers
intact:
<?php
function clean_num($num){
return trim(trim($num, '0'), '.');
}
echo clean_num('06000.3050');
echo clean_num('500.00');
?>
Output:
6000.305
500
I find it very handy to use when pulling data from decimal fields in MySQL and putting them into
<input> fields. Makes everything cleaner :)
----
Manual Page -- http://www.php.net/manual/en/function.trim.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+54473
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54473&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54473&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54473&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54473&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54473&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54473&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+54473&report=yes
Search -- http://master.php.net/manage/user-notes.php