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 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 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. 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". 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
Archived
This topic is now archived and is closed to further replies.