Delete first number if 0

Asked

Viewed 39 times

2

How do I delete the first number if it equals "0", for example, I have the following number "0123" would be "123", if it were "123" nothing would happen.

1 answer

5


You can use the ltrim, by default it removes spaces at the beginning of the text. However, specifying the last argument, it will remove the specified characters if they appear at the beginning of the string:

ltrim ('0123', '0');

This will remove all 0 be submitted before.


Examples:

Original: 00000123
ltrim:    123

Original: 101
ltrim:    101

Original: 014410
ltrim:    14410

Original: 100
ltrim:    100

Original: 00100
ltrim:    100

Test this


If the value is 0 it will also remove, ie 0, 00 or 00000 (...) will become emptiness, an alternative, if int is to use (int)ltrim ($numero, '0')

  • 1

    I used and solved my problem. Thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.