moisesbr Posted August 18, 2013 Share Posted August 18, 2013 Hi User may insert numbers as: 000000000004545498 00000003585498 No matter what he types, I need always remove zero from left side of variables. (char type) Is there a ready function for this, ou how can I do it ? Moises Quote Link to comment https://forums.phpfreaks.com/topic/281314-trimmer-zeros-from-char-variable/ Share on other sites More sharing options...
Barand Posted August 18, 2013 Share Posted August 18, 2013 couple of ways $a = '00000000000123'; $n = intval($a); echo $n; // 123 $n = trim($a, '0'); echo $n; // 123 Quote Link to comment https://forums.phpfreaks.com/topic/281314-trimmer-zeros-from-char-variable/#findComment-1445671 Share on other sites More sharing options...
.josh Posted August 18, 2013 Share Posted August 18, 2013 trim will trim from beginning and end. ltrim will trim only from the beginning. Quote Link to comment https://forums.phpfreaks.com/topic/281314-trimmer-zeros-from-char-variable/#findComment-1445676 Share on other sites More sharing options...
Barand Posted August 18, 2013 Share Posted August 18, 2013 Good thinking, I hadn't considered "00000000001230". Quote Link to comment https://forums.phpfreaks.com/topic/281314-trimmer-zeros-from-char-variable/#findComment-1445677 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.