Find character position in string and remove it

0

I have a complicated problem to solve, there are 3 types of variables that receive data via post example:

$mes = "08";
$mes = "10";
$mes = "12";

In the case of 3 different string types, I need 0 to be removed when it is the first occurrence in the string (for the initial character) I have already tried in several ways until it explodes in the data entry, but this affects all the data of the input and it would not be necessary because this validation should only occur from number 01 to 09 leaving only unit 1 to 9. How can I do this?

    
asked by anonymous 27.11.2017 / 07:52

1 answer

4

You do not need to use a function to remove zero from the first position. You can do the typing using int .

$mes = "08"; // string(2) "08"
$mes = "10"; // string(2) "10"
$mes = "12"; // string(2) "12"

$mes = (int) "08"; // int(8)
$mes = (int) "10"; // int(10)
$mes = (int) "12"; // int(12)
    
27.11.2017 / 10:21