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 extension from string in PHP?
- Remove new lines from string in PHP
- How to remove the first character of string in PHP?
- How to remove line breaks from the string in PHP?
- How to remove all non-printable characters in a string in PHP?
- How to remove portion of a string after a certain character in PHP?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.