php show dates and times and phone in formats

Asked

Viewed 26 times

1

precios mostrar na tela algumas informaçoes tipo:

$time = '120034' $date = '20170508' $mes = '201704' $hunger = '62992161424'

how do I show like this echo $hour 12:00:34 echo $date 08/05/2017 echo $mes 04/2017 echo $fone 62-99216-1424

echo date(’m/y',strtotime in the month does not work The only thing that worked was the value using format

1 answer

1

Check it out at Ideone

$hora = '120034';
$data = '20170508';
$mes = '201704';
$fome = '62992161424';

$array = str_split($hora, 2); 
$string = implode(":", $array);
echo $string; 

$ano = substr($data, 0, 4);
$mez = substr($data, 4, 2);
$dia = substr($data, 6, 2);
$string = $dia . "/" . $mez . "/" . $ano;
echo $string;

$ano = substr($mes, 0, 4);
$month = substr($mes, 4, 2);
$string = $month . "-" . $ano;
echo $string;

$dois = substr($fome, 0, 2);
$cinco = substr($fome, 2, 5);
$quatro = substr($fome, 7, 4);

$string = $dois . "-" . $cinco . "-" . $quatro;
echo $string;
  • str_split - Converts a string to an array with a predetermined length of each array element
  • replace() Returns a part of a string

test in the desired PHP version here

Browser other questions tagged

You are not signed in. Login or sign up in order to post.