w3resource
php Programming Exercies

PHP String Exercises : Remove all leading zeroes from a string

PHP String: Exercise-19 with Solution

Write a PHP script to remove all leading zeroes from a string.

Original String : '000547023.24'

Pictorial Presentation:

PHP String Exercises: Get the first word of a sentence

Sample Solution:

PHP Code:

<?php
$x = '000547023.24';
$str1 = ltrim($x, '0');
echo $str1."\n";
?>

Sample Output:

547023.24

Flowchart :

Flowchart: Remove all leading zeroes from a string

PHP Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a PHP script to get the first word of a sentence.
Next: Write a PHP script to remove part of a string.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming