How to convert a value (which appears to be an octal) to string literal in PHP (5.6)? Example:
//considere $mes=08; ou $mes=09;
$mes = 08;
echo $mes; // Retorna 0
$result = (string) $mes;
echo $result; // Retorna 0
$result = sprintf('%o', $mes);
echo $result; // Retorna 0
$result = base_convert($mes, 8, 10);
echo $result; // Retorna 0
The value you'd like to find for $ result is '08'
(String).
Example usage 1:
$mes = (string) 08;
....
public function mesPorExtenso($mes) {
switch ($mes) {
case '08': //Não entra no case porque $mes é 0
$mes = "Agosto";
break;
}
}
...
Example usage 2:
$mes = 08;
....
public function mesPorExtenso($mes) {
switch ($mes) {
case 08: // PHP Parse error: Invalid numeric literal
$mes = "Agosto";
break;
}
}
...
What is the correct way to convert the 08 value to a string '08'?
The mesPorExtension () method is called dozens of times,
The value is defined by the caller.
I just want to make sure the $mes
variable is a string.