note 21226 deleted from function.str-pad by cmb
| From: | cmb@php.net | Date: | Mon, 31 Aug 2015 21:04:53 +0000 |
| Subject: | note 21226 deleted from function.str-pad by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-203543@lists.php.net to get a copy of this message | ||
Note Submitter: jared at dctkc dot com
----
matthew.somerville's code did NOT work for me.
neither did bert@catsburg.com's.
neither did any other documentation.
(if I isolated the code by itself, they all worked; but in the context I was using it, $value was
numeric, and there is NO WAY to force it to be a string in PHP).
I had to roll my own. I used 'trim' to _force_
the value of $value to be string, because as
long as PHP thought it was numeric, I could
not use any form of left-padding with zeros.
This worked (I use sprintf to left-pad
$value with zeros to a length of 4):
sprintf("%04s",trim($value));