I have the following string :
$valor = "0050";
How do I insert two points after the second house and stay this way?
00:50
I have the following string :
$valor = "0050";
How do I insert two points after the second house and stay this way?
00:50
If what you have is
$valor = "0050";
Just do it like this:
$valor = "00:50";
If what you have is a variable that has 4 unknown characters and you want to separate them, just do
$valor = substr($valor, 0, 2) . ":" . substr($valor, 2);
If you do not know well the criteria it is difficult to solve, you would have to decide a rule.
Another way to resolve this problem is to use the substr_replace () function. What makes it work the way you want it is to report the fourth argument as zero. This will add the character in the position defined in the third argument (in this example to two)
$valor = '0099';
echo substr_replace($valor, ':', 2, 0);