Jump to content

[SOLVED] Explode Problem


xshanelarsonx

Recommended Posts

This will only show the day, and month. Why won't the year show?

 

<?php
$date = "22/2/2007";
$splitdate = explode("/", $date);
$day = $splitdate[count(splitdate) -1];
$month = $splitdate[count(splitdate) -0];
$year = $splitdate[count(splitdate) -3];
echo "Date: $date<br>
Day: $day<br>
Month: $month<br>
Year: $year";
?>

Link to comment
https://forums.phpfreaks.com/topic/39711-solved-explode-problem/
Share on other sites

The year is set to -3 try -2 instead.

 

This code is a little tidier...

<?php
  $date = "22/2/2007";
  $splitdate = explode("/", $date);
  $day = $splitdate[0];
  $month = $splitdate[1];
  $year = $splitdate[2];
  echo "Date: $date<br>
  Day: $day<br>
  Month: $month<br>
  Year: $year";
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.