Given a number in string format and the task is to remove all leading zeros from the given string in PHP.
Input : str = 00006665555 Output : 6665555 Input : str = 00775505 Output : 775505
Method 1: Using ltrim() function: The ltrim() function is used to remove whitespaces or other characters (if specified) from the left side of a string.
ltrim( "string", "character which to be remove from the left side of string");
Method 2: First convert the given string into number typecast the string to int which will automatically remove all the leading zeros and then again typecast it to string to make it string again.
- Format a number with leading zeros in PHP
- How to remove the first character of string in PHP?
- Remove new lines from string in PHP
- How to remove extension from string in PHP?
- How to Remove Special Character from String in PHP ?
- How to remove all white spaces from a string in PHP ?
- How to remove control characters from PHP string ?
- How to remove portion of a string after a certain character in PHP?
- How to remove line breaks from the string in PHP?
- How to remove all non-printable characters in a string in PHP?