I have a string which contains only numbers. Now I want to remove all leading 0s from that string
For example:
input: 000000001230
output: 1230
input: 01000
output: 1000
Is there any function in PHP/Zend for this?
Thanks
I have a string which contains only numbers. Now I want to remove all leading 0s from that string
For example:
input: 000000001230
output: 1230
input: 01000
output: 1000
Is there any function in PHP/Zend for this?
Thanks
No. There is only Zend_Filter_StringTrim
, but that does not ltrim
, but preg_replace
(unicode aware though) from both ends. Either
use Zend_Filter_Callback
:
echo Zend_Filter::filterStatic('000111000', 'Callback', array('ltrim', '0'));
// gives 111000
or with a filter instance
$trimmer = new Zend_Filter_Callback('ltrim', '0');
echo $trimmer->filter('000111000'); // gives 111000
This way you could use it in a Filter chain.
Can't you just cast to int?
$s = '00000414';
print (int)$s; // 414