php show date and time and handset in formats

1

prices display on the screen some information type:

$ time = '120034' $ data = '20170508' $ mes = '201704' $ hungry = '62992161424'

How do I show it like this? I echo $ 12:00. echo $ data 08/05/2017 echo $ 04/2017 echo $ phone 62-99216-1424

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

    
asked by anonymous 02.12.2017 / 19:09

1 answer

1

See it on 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
  • substr () Returns a part of a string

test on desired PHP version here

    
02.12.2017 / 20:09