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.
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.
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.
Original: 00000123
ltrim: 123
Original: 101
ltrim: 101
Original: 014410
ltrim: 14410
Original: 100
ltrim: 100
Original: 00100
ltrim: 100
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')