I have a simple html dom query which read informations from a football fixtures source, and I loading also a json source.
Here is my full code:
<?php
header('Content-Type: text/html; charset=utf-8');
ini_set("user_agent", "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.60 Safari/537.17");
include_once('simple_html_dom.php');
ini_set('display_errors', true);
error_reporting(E_ALL);
$str = file_get_contents('general.json');
$json = json_decode($str,true);
$filename = "source.html";
$html = file_get_html($filename);
class matches {
var $day;
var $kickofftime;
var $title;
function matches ($day, $kickofftime, $tip){
$this->day=$day;
$this->kickofftime=$kickofftime;
$this->title=$title;
return $this;
}
}
$i=0;
$day=$html->find('h1',0);
$day->plaintext;
$day=str_replace("<h1>TODAY FOOTBALL FIXTURES: ","", $day);
$day=str_replace("</h1>","", $day);
$matchday = str_replace(array('MONDAY ', 'TUESDAY ', 'WEDNESDAY ', 'THURSDAY ', 'FRIDAY ', 'SATURDAY ', 'SUNDAY '), '', $day);
$matchday=str_replace(" ","-", $matchday);
$matchday=date('Y-m-d', strtotime($matchday));
foreach($html->find('table.fixtures') as $matches)
{
foreach ($matches->find('tr[class=a1],tr[class=a2]') as $matchesTR) {
$kickofftime=$matchesTR->find('td[class=a11],td[class=a21]',0)->plaintext;
$kodate = date('Y-m-d H:i:s', strtotime("$matchday $kickofftime +1 hour"));
$result=$matchesTR->find('td');
echo $kodate;
echo $result[6]->plaintext.'<br>' ;
$i++;
}
}
//Here is the 2nd foreach with the data of JSON source:
foreach($json as $key => $value) {
$value = json_decode($value, true);
echo $value["country"] . ", " . $value["competition"] . " " . $value["club"] . "<br>";
}
// clean up memory
$html->clear();
unset($html);
?>
The current results from the simple html dom html source:
2014-12-23 20:00:00 2-1
2014-12-23 11:00:00 3-1
2014-12-26 08:00:00 1-1
The result from the JSON source:
America Copa America Boca Juniors
Europe Bundesliga Hannover
Asia JLeague Nagoya
I would like to combine these two results in one foreach and I would like to get this result:
2014-12-23 20:00:00 2-1 America Copa America Boca Juniors
2014-12-23 11:00:00 3-1 Europe Bundesliga Hannover
2014-12-26 08:00:00 1-1 Asia JLeague Nagoya
I hope that there is some expert who can help for me because I tried a lot of variation but without result. Many thanks!
$j=0;
$jsonDecodedArray=$json;
foreach($html->find('table.fixtures') as $matches)
{
foreach ($matches->find('tr[class=a1],tr[class=a2]') as $matchesTR) {
$kickofftime=$matchesTR->find('td[class=a11],td[class=a21]',0)->plaintext;
$kodate = date('Y-m-d H:i:s', strtotime("$matchday $kickofftime +1 hour"));
$result=$matchesTR->find('td');
echo $kodate;
echo $result[6]->plaintext." ";
echo $jsonDecodedArray[$j]["country"] . ", " . $jsonDecodedArray[$j]["competition"] . " " . $jsonDecodedArray[$j]["club"] . "<br>"; ;
$i++;
$j++;
}
}
Related
I'm stuck in my php script for a blog where I want to display the time and date for all the articles. I created a function but I don't know why it doesn't want to work:
function articles(){
global $bdd;
$articles = $bdd->query("SELECT id, titre, accroche, contenu, publication, image FROM articles");
$articles = $articles->fetchAll();
return $articles;
}
function formattage_date($publication){
$publication = explode(" ", $publication);
$date = explode("-", $publication[0]);
$heure = explode(":", $publication[1]);
$mois = ["", "janvier", "fevrier", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "decembre"];
$resultat = $date[2] . ' ' . $mois[$date[1]] . ' ' . $date[0] . ' à ' . $heure[0] . 'h' . $heure[1];
return $resultat;
}
When I want to use $mois, php says: Notice: Undefined index: 03 in C:\wamp\www\entertheletter.dev\fonctions\blog.php on line 18
Your problem is the following;
$mois[$date[1]]
The date string from the database is zerofilled if the value is below 10. So assume that the month is january (janvier), you get 01 instead of 1. When accessing the $mois array with that index, it is not able to find it because 01 is not a valid index.
To fix this, remove the first 0 if the date is zerofilled. Or just cast it to int like
$mois[(int)$date[1]]
you can try this function where i have added ltrim function in $mois array we have to converted 01 to 0 because array index start from 0,1,2 ...
so we have to remove 0 from 01.
function formattage_date($publication){
$publication = explode(" ", $publication);
$date = explode("-", $publication[0]);
$heure = explode(":", $publication[1]);
$mois = ["", "janvier", "fevrier", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "decembre"];
$resultat = $date[2] . ' ' . $mois[ltrim($date[1],0)] . ' ' . $date[0] . ' à ' . $heure[0] . 'h' . $heure[1];
return $resultat;
}
I am trying to update all of the date fields in the database to add 5 days to each date in all tables.
I managed to pull the dates and row id into an array then generate a SQL code statement to update them. However, each table has a different date format some with time included some without. I want to add 5 days to a date then save it back. At the moment I can do this if all dates have the same format but that's not good enough to solve my problem.
What I want is a code that can generate string format from a date string. For example:
Date String 2014-12-04 I want the code to say this date has Y-m-d format. If date string is 2017-04-03 11:11:48.653 I want the code to say this date format is Y-m-d h:i:s.
If you don't need to preserve the format (i.e. you can change the format in the database while adding five days), you can just throw the string at strtotime. It will try and detect the format, if possible:
$timestamp = strtotime($string_with_unknown_format);
Alternatively, you can check for different formats with regex:
function extractDateTimeFormat($string) {
if (preg_match('/^\d{4}-\d{2}-\d{2}$/', $string))
return 'Y-m-d';
if (preg_match('/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/', $string))
return 'Y-m-d H:i:s';
if (preg_match('/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}$/', $string))
return 'Y-m-d H:i:s.v';
if (preg_match('/^\d{2}\/\d{2}\/\d{4}$/', $string))
return 'm/d/Y';
if (preg_match('/^\d{2}\.\d{2}\.\d{4}$/', $string))
return 'd.m.Y';
}
However, that could get tiresome, depending on how many formats you expect. On the other hand - how many can there be?
The next alternative would be to replace the digits by their placeholders directly in the string - this would be more flexible, but possibly a little less predictable. In this case, the order of the lines is important. If you need to add 12 hour formats (AM / PM), you need to insert the lines prior to the line for H:i:s or it won't work.
function extractDateTimeFormat($string) {
$string = preg_replace('/\b\d{4}-\d{2}-\d{2}\b/', 'Y-m-d');
$string = preg_replace('/\b\d{2}\/\d{2}\/\d{4}\b/', 'm/d/Y');
$string = preg_replace('/\b\d{2}\.\d{2}\.\d{4}\b/', 'd.m.Y');
$string = preg_replace('/\b\d{2}:\d{2}\b:\d{2}\b/', 'H:i:s');
$string = preg_replace('/\b\d{2}:\d{2}\b/', 'H:i');
$string = preg_replace('/\.\d{3}\b/', '.v');
if (preg_match('/\d/', $string)
return false;
return $string;
}
That way, you'll detect date and time formats independently so you don't have to think of every possible combination.
You'll have to check with your live data which method works better.
The best way to format dates and know what date format, solution for those who are developing in date format. I also add the ISO8601 date format
function date_extract_format( $d, $null = '' ) {
// check Day -> (0[1-9]|[1-2][0-9]|3[0-1])
// check Month -> (0[1-9]|1[0-2])
// check Year -> [0-9]{4} or \d{4}
$patterns = array(
'/\b\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3,8}Z\b/' => 'Y-m-d\TH:i:s.u\Z', // format DATE ISO 8601
'/\b\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])\b/' => 'Y-m-d',
'/\b\d{4}-(0[1-9]|[1-2][0-9]|3[0-1])-(0[1-9]|1[0-2])\b/' => 'Y-d-m',
'/\b(0[1-9]|[1-2][0-9]|3[0-1])-(0[1-9]|1[0-2])-\d{4}\b/' => 'd-m-Y',
'/\b(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])-\d{4}\b/' => 'm-d-Y',
'/\b\d{4}\/(0[1-9]|[1-2][0-9]|3[0-1])\/(0[1-9]|1[0-2])\b/' => 'Y/d/m',
'/\b\d{4}\/(0[1-9]|1[0-2])\/(0[1-9]|[1-2][0-9]|3[0-1])\b/' => 'Y/m/d',
'/\b(0[1-9]|[1-2][0-9]|3[0-1])\/(0[1-9]|1[0-2])\/\d{4}\b/' => 'd/m/Y',
'/\b(0[1-9]|1[0-2])\/(0[1-9]|[1-2][0-9]|3[0-1])\/\d{4}\b/' => 'm/d/Y',
'/\b\d{4}\.(0[1-9]|1[0-2])\.(0[1-9]|[1-2][0-9]|3[0-1])\b/' => 'Y.m.d',
'/\b\d{4}\.(0[1-9]|[1-2][0-9]|3[0-1])\.(0[1-9]|1[0-2])\b/' => 'Y.d.m',
'/\b(0[1-9]|[1-2][0-9]|3[0-1])\.(0[1-9]|1[0-2])\.\d{4}\b/' => 'd.m.Y',
'/\b(0[1-9]|1[0-2])\.(0[1-9]|[1-2][0-9]|3[0-1])\.\d{4}\b/' => 'm.d.Y',
// for 24-hour | hours seconds
'/\b(?:2[0-3]|[01][0-9]):[0-5][0-9](:[0-5][0-9])\.\d{3,6}\b/' => 'H:i:s.u',
'/\b(?:2[0-3]|[01][0-9]):[0-5][0-9](:[0-5][0-9])\b/' => 'H:i:s',
'/\b(?:2[0-3]|[01][0-9]):[0-5][0-9]\b/' => 'H:i',
// for 12-hour | hours seconds
'/\b(?:1[012]|0[0-9]):[0-5][0-9](:[0-5][0-9])\.\d{3,6}\b/' => 'h:i:s.u',
'/\b(?:1[012]|0[0-9]):[0-5][0-9](:[0-5][0-9])\b/' => 'h:i:s',
'/\b(?:1[012]|0[0-9]):[0-5][0-9]\b/' => 'h:i',
'/\.\d{3}\b/' => '.v'
);
//$d = preg_replace('/\b\d{2}:\d{2}\b/', 'H:i',$d);
$d = preg_replace( array_keys( $patterns ), array_values( $patterns ), $d );
return preg_match( '/\d/', $d ) ? $null : $d;
}
function date_formating( $date, $format = 'd/m/Y H:i', $in_format = false, $f = '' ) {
$isformat = date_extract_format( $date );
$d = DateTime::createFromFormat( $isformat, $date );
$format = $in_format ? $isformat : $format;
if ( $format ) {
if ( in_array( $format, [ 'Y-m-d\TH:i:s.u\Z', 'DATE_ISO8601', 'ISO8601' ] ) ) {
$f = $d ? $d->format( 'Y-m-d\TH:i:s.' ) . substr( $d->format( 'u' ), 0, 3 ) . 'Z': '';
} else {
$f = $d ? $d->format( $format ) : '';
}
}
return $f;
} // end function
function date_convert_format( $old = '' ) {
$old = trim( $old );
if ( preg_match( '/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/', $old ) ) { // MySQL-compatible YYYY-MM-DD format
$new = $old;
} elseif ( preg_match( '/^[0-9]{4}-(0[1-9]|[1-2][0-9]|3[0-1])-(0[1-9]|1[0-2])$/', $old ) ) { // DD-MM-YYYY format
$new = substr( $old, 0, 4 ) . '-' . substr( $old, 5, 2 ) . '-' . substr( $old, 8, 2 );
} elseif ( preg_match( '/^(0[1-9]|[1-2][0-9]|3[0-1])-(0[1-9]|1[0-2])-[0-9]{4}$/', $old ) ) { // DD-MM-YYYY format
$new = substr( $old, 6, 4 ) . '-' . substr( $old, 3, 2 ) . '-' . substr( $old, 0, 2 );
} elseif ( preg_match( '/^(0[1-9]|[1-2][0-9]|3[0-1])-(0[1-9]|1[0-2])-[0-9]{2}$/', $old ) ) { // DD-MM-YY format
$new = substr( $old, 6, 4 ) . '-' . substr( $old, 3, 2 ) . '-20' . substr( $old, 0, 2 );
} else { // Any other format. Set it as an empty date.
$new = '0000-00-00';
}
return $new;
}
$date_1 = '13/05/2020 19:20:15.156457';
$date_2 = '25-05-2020 10:20';
$date_3 = '2020.05.20 10:20';
$date_4 = '2020.25.05 18:20';
$date_5 = '05/05/2020 12:20';
$date_6 = '05.05.2020 10:20';
$date_7 = '2020-20-05';
//-----------------------------
echo "1($date_1): " . date_formating( $date_1, false, true ) . PHP_EOL;
// echo-> isformat: d/m/Y H:i:s.u
// 1(13/05/2020 19:20:15): 2020-05-13 19:20
echo "2($date_2): " . date_formating( $date_2 ) . PHP_EOL;
// echo-> isformat: d-m-Y H:i
// 2(25-05-2020 10:20): 25/05/2020 10:20
echo "3($date_3): " . date_formating( $date_3 ) . PHP_EOL;
// echo-> isformat: Y.m.d H:i
// 3(2020.05.20 10:20): 20/05/2020 10:20
echo "4($date_4): " . date_formating( $date_4 ) . PHP_EOL;
// echo-> isformat: Y.d.m H:i
// 4(2020.25.05 18:20): 25/05/2020 18:20
echo "5($date_5): " . date_formating( $date_5 ) . PHP_EOL;
// echo-> isformat: d/m/Y H:i
// 5(05/05/2020 12:20): 05/05/2020 12:20
echo "6($date_6): " . date_formating( $date_6 ) . PHP_EOL;
// echo-> isformat: d.m.Y H:i
// 6(05.05.2020 10:20): 05/05/2020 10:20
echo "7($date_7): " . date_formating( $date_7, false, true ) . PHP_EOL;
// echo-> isformat: Y-d-m
// 7(2020-20-05): 2020-20-05
echo "Date ISO8601: = " . date_formating( $date_1, 'DATE_ISO8601' ) . PHP_EOL;
// echo-> isformat: d/m/Y H:i:s.u
// Date ISO8601: = 2020-05-13T19:20:15.156Z
echo "7($date_7): = " . date_convert_format( $date_7 );
// 7(2020-20-05): = 2020-20-05
I have a simple html dom query which read information from a football fixtures source, and I am loading also a json source.
Here is my full code:
<?php
header('Content-Type: text/html; charset=utf-8');
ini_set("user_agent", "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.60 Safari/537.17");
include_once('simple_html_dom.php');
ini_set('display_errors', true);
error_reporting(E_ALL);
$str = file_get_contents('general.json');
$json = json_decode($str,true);
$filename = "source.html";
$html = file_get_html($filename);
class matches {
var $day;
var $kickofftime;
var $result;
function matches ($day, $kickofftime, $result){
$this->day=$day;
$this->kickofftime=$kickofftime;
$this->result=$result;
return $this;
}
}
$i=0;
$day=$html->find('h1',0);
$day->plaintext;
$day=str_replace("<h1>TODAY FOOTBALL FIXTURES: ","", $day);
$day=str_replace("</h1>","", $day);
$matchday = str_replace(array('MONDAY ', 'TUESDAY ', 'WEDNESDAY ', 'THURSDAY ', 'FRIDAY ', 'SATURDAY ', 'SUNDAY '), '', $day);
$matchday=str_replace(" ","-", $matchday);
$matchday=date('Y-m-d', strtotime($matchday));
foreach($html->find('table.fixtures') as $matches)
{
foreach ($matches->find('tr[class=a1],tr[class=a2]') as $matchesTR) {
$kickofftime=$matchesTR->find('td[class=a11],td[class=a21]',0)->plaintext;
$kodate = date('Y-m-d H:i:s', strtotime("$matchday $kickofftime +1 hour"));
$result=$matchesTR->find('td');
echo $kodate;
echo $result[6]->plaintext.'<br>' ;
$i++;
}
}
//Here is the 2nd foreach with the data of JSON source:
foreach($json as $key => $value) {
$value = json_decode($value, true);
echo $value["country"] . ", " . $value["competition"] . " " . $value["club"] . "<br>";
}
// clean up memory
$html->clear();
unset($html);
?>
The current results from the simple html dom html source:
2014-12-23 20:00:00 2-1
2014-12-23 11:00:00 3-1
2014-12-26 08:00:00 1-1
The result from the JSON source:
America Copa America Boca Juniors
Europe Bundesliga Hannover
Asia JLeague Nagoya
I would like to combine these two results in one foreach and I would like to get this result:
2014-12-23 20:00:00 2-1 America Copa America Boca Juniors
2014-12-23 11:00:00 3-1 Europe Bundesliga Hannover
2014-12-26 08:00:00 1-1 Asia JLeague Nagoya
I hope one can help me because I tried a lot of variation but without result. Many thanks!
You can use array_map function of PHP.
Lets say your values are in arrays $a, $b:
$mapFunc = function($n, $m) {
return "$n $m";
};
$c = array_map($mapFunc, $a, $b);
I have a simple html dom query which read informations from a football fixtures source, and I loading also a json source.
Here is my full code:
<?php
header('Content-Type: text/html; charset=utf-8');
ini_set("user_agent", "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.60 Safari/537.17");
include_once('simple_html_dom.php');
ini_set('display_errors', true);
error_reporting(E_ALL);
$str = file_get_contents('general.json');
$json = json_decode($str,true);
$filename = "source.html";
$html = file_get_html($filename);
class matches {
var $day;
var $kickofftime;
var $result;
function matches ($day, $kickofftime, $tip){
$this->day=$day;
$this->kickofftime=$kickofftime;
$this->result=$result;
return $this;
}
}
$i=0;
$day=$html->find('h1',0);
$day->plaintext;
$day=str_replace("<h1>TODAY FOOTBALL FIXTURES: ","", $day);
$day=str_replace("</h1>","", $day);
$matchday = str_replace(array('MONDAY ', 'TUESDAY ', 'WEDNESDAY ', 'THURSDAY ', 'FRIDAY ', 'SATURDAY ', 'SUNDAY '), '', $day);
$matchday=str_replace(" ","-", $matchday);
$matchday=date('Y-m-d', strtotime($matchday));
foreach($html->find('table.fixtures') as $matches)
{
foreach ($matches->find('tr[class=a1],tr[class=a2]') as $matchesTR) {
$kickofftime=$matchesTR->find('td[class=a11],td[class=a21]',0)->plaintext;
$kodate = date('Y-m-d H:i:s', strtotime("$matchday $kickofftime +1 hour"));
$result=$matchesTR->find('td');
echo $kodate;
echo $result[6]->plaintext.'<br>' ;
$i++;
}
}
//Here is the 2nd foreach with the data of JSON source:
foreach($json as $key => $value) {
$value = json_decode($value, true);
echo $value["country"] . ", " . $value["competition"] . " " . $value["club"] . "<br>";
}
// clean up memory
$html->clear();
unset($html);
?>
The current results from the simple html dom html source:
2014-12-23 20:00:00 2-1
2014-12-23 11:00:00 3-1
2014-12-26 08:00:00 1-1
The result from the JSON source:
America Copa America Boca Juniors
Europe Bundesliga Hannover
Asia JLeague Nagoya
I would like to combine these two results in one foreach and I would like to get this result:
2014-12-23 20:00:00 2-1 America Copa America Boca Juniors
2014-12-23 11:00:00 3-1 Europe Bundesliga Hannover
2014-12-26 08:00:00 1-1 Asia JLeague Nagoya
I hope that there is some expert who can help for me because I tried a lot of variation but without result. I got some advice (with code) from experts, but there was everytime errors. With my code there is no error, but I need other solution because I would like to put all variables to one foreach. Many thanks, I hope that somebody could help me with code, because I am not on high level at php. Thanks again!
I would like to put the two foreach into one foreach, but I don't want to create a new array because I not need.
Assuming you will always have the same amount of items in each and that they match 1 to 1, 2 to 2, you can do this:
$htmlDates = array();
$jsonLeag = array();
foreach($html->find('table.fixtures') as $matches) {
foreach($matches->find('tr[class=a1],tr[class=a2]') as $matchesTR) {
$kickofftime=$matchesTR->find('td[class=a11],td[class=a21]',0)->plaintext;
$kodate = date('Y-m-d H:i:s', strtotime("$matchday $kickofftime +1 hour"));
$result=$matchesTR->find('td');
//echo $kodate;
//echo $result[6]->plaintext.'<br>' ;
$htmlDates[] = $kodates;
}
}
//Here is the 2nd foreach with the data of JSON source:
foreach($json as $key => $value) {
$value = json_decode($value, true);
//echo $value["country"] . ", " . $value["competition"] . " " . $value["club"] . "<br>";
$jsonLeag[] = $value["country"] . ", " . $value["competition"] . " " . $value["club"];
}
if(count($htmlDates) < count($jsonLeag)){
for($i=0;$i<count($htmlData);$i++){
echo $htmlData[$i] . " " . $jsonLeag[$i] . "<br />\r\n";
}
} else {
for($i=0;$i<count($jsonLeag);$i++){
echo $htmlData[$i] . " " . $jsonLeag[$i] . "<br />\r\n";
}
}
Since you have the nested list first and nothing ties the two data sets together, there is no simple way to run one loop and get the data from both. It's easier to push the data you want into an array for each set, and then walk both arrays with one counter. The caveat here is that if one has an extra element, you will get missing results or errors.
Save keys of json arrays and use the next in each loop.
$json_keys = array_keys($json);
$i_key = 0;
foreach($html->find('table.fixtures') as $matches)
{
foreach ($matches->find('tr[class=a1],tr[class=a2]') as $matchesTR) {
$kickofftime=$matchesTR->find('td[class=a11],td[class=a21]',0)->plaintext;
$kodate = date('Y-m-d H:i:s', strtotime("$matchday $kickofftime +1 hour"));
$result=$matchesTR->find('td');
echo $kodate;
echo $result[6]->plaintext.
$value = json_decode($json[$json_keys[$i_key++]], true);
echo $value["country"] . ", " . $value["competition"] . " " . $value["club"] . "<br>";
$i++;
}
}
// clean up memory
$html->clear();
unset($html);
There are many other variants - use array_shift(), next()... I've written the first come in mind
I'm embedding dates from google calendar into a website, and it's all working, with the exception of sorting. For some reason, it sorts into reverse-chronological order, when I'd really just like it to be normal chronological (first event first).
this is the output:
August 11th: Intern depart
August 6th: Last Day of Summer Camp
July 7th: Ignore this
July 6th: This is another example event
July 5th: example
June 28th: Summer Camp Starts
June 24th: Summer Pool Party
June 21st: Intern arrival date
June 15th: Assistant Director Arrival Date
June 14th: Director's training begins
May 26th: Brainstorm day for directors
I'm really still just learning a lot of this stuff- thanks for the help in advance!
<?php
$confirmed = 'http://schemas.google.com/g/2005#event.confirmed';
$three_months_in_seconds = 60 * 60 * 24 * 28 * 3;
$three_months_ago = date("Y-m-d\Th:i:sP", time() - 172800);
$three_months_from_today = date("Y-m-d\Th:i:sP", time() + $three_months_in_seconds);
$feed = "http://www.google.com/calendar/feeds/qp6o02ka3iaoem2kr8odga6j7s%40group.calendar.google.com/" .
"public/full?orderby=starttime&singleevents=true&" .
"start-min=" . $three_months_ago . "&" .
"start-max=" . $three_months_from_today;
$doc = new DOMDocument();
$doc->load( $feed );
$entries = $doc->getElementsByTagName( "entry" );
foreach ( $entries as $entry ) {
$status = $entry->getElementsByTagName( "eventStatus" );
$eventStatus = $status->item(0)->getAttributeNode("value")->value;
if ($eventStatus == $confirmed) {
$titles = $entry->getElementsByTagName( "title" );
$title = $titles->item(0)->nodeValue;
$times = $entry->getElementsByTagName( "when" );
$startTime = $times->item(0)->getAttributeNode("startTime")->value;
$when = date( "F jS", strtotime( $startTime ) );
$whentime = date( "g:ia", strtotime ( $startTime ) );
$places = $entry->getElementsByTagName( "where" );
$where = $places->item(0)->getAttributeNode("valueString")->value;
$links = $entry->getElementsByTagName( "link" );
$link = $links->item(0)->nodeValue;
print $when;
if ($whentime == "12:00am"){
;
}
else{
echo " at ";
print $whentime;
}
echo ": ";
echo "<b>";
print $title . "\n";
echo "</b>";
echo " ";
if(empty($where)){;}else{
echo "<br />";
print $where . "\n";
}
print $link;
print "<br />";
}
}
?>
Add &sortorder=descending to your feed URL. You can find documentation for this in the FAQ