Trim any zeros at the beginning of a string using PHP Trim any zeros at the beginning of a string using PHP php php

Trim any zeros at the beginning of a string using PHP


You can use ltrim() and pass the characters that should be removed as second parameter:

$input = ltrim($input, '0');// 000123 -> 123

ltrim only removes the specified characters (default white space) from the beginning (left side) of the string.


ltrim($usernumber, "0");

should do the job, according to the PHP Manual


$number = "004561";$number = intval($number, 10);$number = (string)$number; // if you want it to again be a string