Erase the first number if in case 0

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.     

asked by anonymous 05.05.2017 / 13:03

1 answer

5

You can use ltrim , by default it removes spaces at the beginning of the text. However, by 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 from before.

Examples:

Original: 00000123
ltrim:    123

Original: 101
ltrim:    101

Original: 014410
ltrim:    14410

Original: 100
ltrim:    100

Original: 00100
ltrim:    100

Try This

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

    
05.05.2017 / 13:16