When communicating with XML, ISO 8601 Format time string is used. In case of using xmlrpc, it contains ISO 8601 Format time string conversion module such as iso8601_encode, and ISO8601_decode.
If you don't use xmlrpc module, you can declare below module in order to use ISO 8601 Format time string conversion module. Of course, if your PHP supports the function, you don't need to declare below functions.
// date helpers
function iso8601_encode($timet, $utc=0) {
// return an ISO8601 encoded string
// really, timezones ought to be supported
// but the XML-RPC spec says:
//
// "Don't assume a timezone. It should be specified by the server in its
// documentation what assumptions it makes about timezones."
//
// these routines always assume localtime unless
// $utc is set to 1, in which case UTC is assumed
// and an adjustment for locale is made when encoding
if (!$utc) {
$t=strftime("%Y%m%dT%H:%M:%S", $timet);
} else {
if (function_exists("gmstrftime"))
// gmstrftime doesn't exist in some versions
// of PHP
$t=gmstrftime("%Y%m%dT%H:%M:%S", $timet);
else {
$t=strftime("%Y%m%dT%H:%M:%S", $timet-date("Z"));
}
}
return $t;
}
function ISO8601_decode($idate, $utc=0) {
// return a timet in the localtime, or UTC
$t=0;
if (ereg("([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})",
$idate, $regs)) {
if ($utc) {
$t=gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
} else {
$t=mktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
}
}
return $t;
}
function iso8601_encode($timet, $utc=0) {
// return an ISO8601 encoded string
// really, timezones ought to be supported
// but the XML-RPC spec says:
//
// "Don't assume a timezone. It should be specified by the server in its
// documentation what assumptions it makes about timezones."
//
// these routines always assume localtime unless
// $utc is set to 1, in which case UTC is assumed
// and an adjustment for locale is made when encoding
if (!$utc) {
$t=strftime("%Y%m%dT%H:%M:%S", $timet);
} else {
if (function_exists("gmstrftime"))
// gmstrftime doesn't exist in some versions
// of PHP
$t=gmstrftime("%Y%m%dT%H:%M:%S", $timet);
else {
$t=strftime("%Y%m%dT%H:%M:%S", $timet-date("Z"));
}
}
return $t;
}
function ISO8601_decode($idate, $utc=0) {
// return a timet in the localtime, or UTC
$t=0;
if (ereg("([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})",
$idate, $regs)) {
if ($utc) {
$t=gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
} else {
$t=mktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
}
}
return $t;
}
As I mentioned, above functions will be very useful if you need to implement RSS, or Sitemap.
Another posts included in "PHP"
| Get the actual filesize for a size above 2GB in Windows (0) | 2008/02/24 |
| How to convert W3C Date Time Format ? (0) | 2008/02/28 |
| How to put timeout when opening URL by fopen ? (0) | 2008/03/31 |
| How to download a file from a certain URL to server ? (0) | 2008/01/21 |
| How to extract file name from given URL ? (0) | 2008/01/21 |
| File downloading via HTTP (0) | 2008/01/21 |
| How to block a connection from the certain site ? (0) | 2008/01/14 |
| XMLRPC example (0) | 2008/01/07 |
Trackback : Cannot send a trackbact to this post.
-
Subject Furniture stores.
2009/01/06 09:20
Furniture stores in michigan. Furniture stores tn. Furniture stores and buford ga. Furniture stores in oahu. Furniture stores.
-
Subject different money making ideas
2010/01/28 23:56
moneyideas
-
Subject different money making ideas
2010/01/29 08:20
moneyideas
-
Subject different money making ideas
2010/01/31 16:43
moneyideas

Prev

Rss Feed