好的,所以我将oscommerce中的products_new.php页面重新输出为rss页面输出,问题是日期格式错误,目前它输出如此
2002年10月2日星期三 使用:
tep_date_long($products_new['products_date_added'])
它必须采用以下格式: 2002年10月2日星期三15:00:00 +0200 这个的PHP是
("D, d M Y H:i:s O", time())
但我不确定如何实现它或更改现有代码
任何想法?
echo '<?xml version="1.0" encoding="ISO-8859-1"?>
<rss version="2.0">
<channel>
<link>http://www.primedelux.com</link>
<language>en-uk</language>
<copyright>Copyright (C) 2011 http://www.primedelux.com</copyright>
<pubDate>' . date("D, d M Y H:i:s O", time()) . '</pubDate>';
?>
<?php
$products_new_array = array();
$products_new_query_raw = "select p.products_id, pd.products_name, p.products_image, p.products_price, p.products_tax_class_id, p.products_date_added, m.manufacturers_name from " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m on (p.manufacturers_id = m.manufacturers_id), " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' order by p.products_date_added DESC, pd.products_name";
$products_new_split = new splitPageResults($products_new_query_raw, MAX_DISPLAY_PRODUCTS_NEW); ?>
<?php
if ($products_new_split->number_of_rows > 0) {
$products_new_query = tep_db_query($products_new_split->sql_query);
while ($products_new = tep_db_fetch_array($products_new_query)) {
if ($new_price = tep_get_products_special_price($products_new['products_id'])) {
$products_price = '<s>' . $currencies->display_price($products_new['products_price'], tep_get_tax_rate($products_new['products_tax_class_id'])) . '</s> <span class="productSpecialPrice">' . $currencies->display_price($new_price, tep_get_tax_rate($products_new['products_tax_class_id'])) . '</span>';
} else {
$products_price = $currencies->display_price($products_new['products_price'], tep_get_tax_rate($products_new['products_tax_class_id']));
}
?>
<?php
echo '<item>';
echo '<title>' . $products_new['products_name'] . '</title>';
echo '<description><![CDATA[' . tep_image('http://www.primedelux.com/images/' . $products_new['products_image']) . ' ]]>' . $products_new['products_name'] . '</description>';
echo '<link>' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products_new['products_id']) . '</link>';
echo '<guid>' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products_new['products_id']) . '</guid>';
echo '<pubDate>' . tep_date_long($products_new['products_date_added']) . '</pubDate>';
echo '</item>';
?>
<?php
}
}
?>
<?php echo '</urlset>';?>
<?php echo '</channel>';?>
<?php echo '</rss>';?>
下面是tep_date_long:
// Output a raw date string in the selected locale date format
// $raw_date needs to be in this format: YYYY-MM-DD HH:MM:SS
function tep_date_long($raw_date) {
if ( ($raw_date == '0000-00-00 00:00:00') || ($raw_date == '') ) return false;
$year = (int)substr($raw_date, 0, 4);
$month = (int)substr($raw_date, 5, 2);
$day = (int)substr($raw_date, 8, 2);
$hour = (int)substr($raw_date, 11, 2);
$minute = (int)substr($raw_date, 14, 2);
$second = (int)substr($raw_date, 17, 2);
return strftime(DATE_FORMAT_LONG, mktime($hour,$minute,$second,$month,$day,$year));
}
答案 0 :(得分:1)
替代:
return strftime(DATE_FORMAT_LONG, mktime($hour,$minute,$second,$month,$day,$year));
使用:
$time= mktime($hour,$minute,$second,$month,$day,$year);
$x= strftime("%a, %d %b %Y %H:%M:%S",$time);
if($x){
return $x;
}else{
return date("D, d M Y H:i:s O", $time);
}
strftime在Windows和Linux中不接受相同的设置,所提供的解决方案是简化,但在手册中找到适合您环境的正确信息。