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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.