Help with substrings!

I have this code snippet :

[code] echo "

$title
Posted by: $posted_name$submitted
Post date: $date

$text $reaction
";[/code]

Where the $date refers to a section at the top saying ‘get_date_archive’ which refers to a script in a file, ‘functions.php’. Here is the code :

[code]function get_date_archive($date) {
$year = substr($date, 0,4);
$month = substr($date, 4,2);
$day = substr($date, 0,4);

$day_array = array(“Monday”, “Tuesday”, “Wednesday”, “Thursday”, “Friday”, “Saturday”, “Sunday”);
$day_text = $day_array[$day - 1];

$month_array = array(“January”, “February”, “March”, “April”, “May”, “June”, “July”, “August”, “September”, “October”, “November”, “December”);
$month_text = $month_array[$month - 1];

return “$day_text $month_text $year”;
}[/code]

For some reason the result in my browser is that it is showing only
Post date; Month, Year (August 2004)
I want it to be :
Post date; eg: Wednesday, 11, March 2004

I think the error lies in the substrings but can anyone edit the code to make it work?[/code]

I think you want to change it to this:

$year = substr($date, 0,4); $month = substr($date, 3,2); $day = substr($date, 5,2);

I’m assuming $date holds something like “20040813”. Remember that the string starts at position 0, so the year will be from 0-3 (4 digits), the month will be from 3-5 (2 digits), and the day will be from 5-7 (2 digits).

Thanks, i finally have that explained. It’s still a bit tricky but im making slooooow progress! Thanks for your help.

Sponsor our Newsletter | Privacy Policy | Terms of Service