如何设?难道这样设不对? date_default_timezone_set('Asia/Shanghai'); 对的话,怎么在Chapter02里的订单例子,时间不显示? 附源码: <?php // create short variable names $tireqty = $_POST['tireqty']; $oilqty = $_POST['oilqty']; $sparkqty = $_POST['sparkqty']; $address = $_POST['address']; $DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT']; date_default_timezone_set('Asia/Shanghai'); //这句是我加的设置时间代码 $date = date('H:i, jS F Y'); ?> <html> <head> <title>Bob's Auto Parts - Order Results</title> </head> <body> <h1>Bob's Auto Parts</h1> <h2>Order Results</h2> <?php echo "<p>Your order is as follows: </p>"; $totalqty = 0; $totalqty = $tireqty + $oilqty + $sparkqty; echo "Items ordered: ".$totalqty."<br />"; if ($totalqty == 0) { echo "You did not order anything on the previous page!<br />"; } else { if ($tireqty > 0) { echo $tireqty." tires<br />"; } if ($oilqty > 0) { echo $oilqty." bottles of oil<br />"; } if ($sparkqty > 0) { echo $sparkqty." spark plugs<br />"; } } $totalamount = 0.00; define('TIREPRICE', 100); define('OILPRICE', 10); define('SPARKPRICE', 4); $totalamount = $tireqty * TIREPRICE + $oilqty * OILPRICE + $sparkqty * SPARKPRICE; $totalamount=number_format($totalamount, 2, '.', ' '); echo "<p>Total of order is $".$totalamount."</p>"; echo "<p>Address to ship to is ".$address."</p>"; $outputstring = $date."\t".$tireqty." tires \t".$oilqty." oil\t" .$sparkqty." spark plugs\t\$".$totalamount ."\t". $address."\n"; // open file for appending @ $fp = fopen("$DOCUMENT_ROOT/../orders/orders.txt", 'ab'); flock($fp, LOCK_EX); if (!$fp) { echo "<p><strong> Your order could not be processed at this time. Please try again later.</strong></p></body></html>"; exit; } fwrite($fp, $outputstring, strlen($outputstring)); flock($fp, LOCK_UN); fclose($fp); echo "<p>Order written.</p>"; ?> </body> </html>
date() 函数前面是中文的空格.
我也是跟着这个PHP圣经学习的,代码和楼主的一样,flock这个函数遇到了问题,提示:
Warning: flock() expects parameter 1 to be resource, boolean given in D:\MyServer\Apache2.2.9\htdocs\study\processorder.php on line 59原函数就是flock($fp,LOCK_EX),我和书上写的一样,然后就是一直报错。高手们能帮忙看看是怎么回事么?谢谢了! 我的代码和12楼的一样,请告诉我应该怎么修改,谢谢了
date_default_timezone_set('Asia/Shanghai');
echo "<p>Order processed at ".date('H:i, jS F Y')."</p>";
Bob's Auto Parts
Order Results
Order processed at ".date('H:i, jS F Y').""; echo "Your order is as follows:
"; $totalqty = 0; $totalqty = $tireqty + $oilqty + $sparkqty; echo "Items ordered: ".$totalqty."
"; if ($totalqty == 0) { echo "You did not order anything on the previous page!
"; } else { if ($tireqty > 0) { echo $tireqty." tires
"; } if ($oilqty > 0) { echo $oilqty." bottles of oil
"; } if ($sparkqty > 0) { echo $sparkqty." spark plugs
"; } } $totalamount = 0.00; define('TIREPRICE', 100); define('OILPRICE', 10); define('SPARKPRICE', 4); $totalamount = $tireqty * TIREPRICE + $oilqty * OILPRICE + $sparkqty * SPARKPRICE; echo "Subtotal: $".number_format($totalamount,2)."
"; $taxrate = 0.10; // local sales tax is 10% $totalamount = $totalamount * (1 + $taxrate); echo "Total including tax: $".number_format($totalamount,2)."
"; if($find == "a") { echo "Regular customer.
"; } elseif($find == "b") { echo "Customer referred by TV advert.
"; } elseif($find == "c") { echo "Customer referred by phone directory.
"; } elseif($find == "d") { echo "Customer referred by word of mouth.
"; } else { echo "We do not know how this customer found us.
"; } ?>
也能正常 显示了。头 疼啊
天啊,到底应当怎样设置?权威的例子尚且如此,其他复言何?
date_default_timezone_set('Asia/Shanghai');
对的话,怎么在Chapter02里的订单例子,时间不显示?
附源码:
<?php
// create short variable names
$tireqty = $_POST['tireqty'];
$oilqty = $_POST['oilqty'];
$sparkqty = $_POST['sparkqty'];
$address = $_POST['address'];
$DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
date_default_timezone_set('Asia/Shanghai'); //这句是我加的设置时间代码
$date = date('H:i, jS F Y');
?>
<html>
<head>
<title>Bob's Auto Parts - Order Results</title>
</head>
<body>
<h1>Bob's Auto Parts</h1>
<h2>Order Results</h2>
<?php echo "<p>Your order is as follows: </p>"; $totalqty = 0;
$totalqty = $tireqty + $oilqty + $sparkqty;
echo "Items ordered: ".$totalqty."<br />";
if ($totalqty == 0) { echo "You did not order anything on the previous page!<br />"; } else { if ($tireqty > 0) {
echo $tireqty." tires<br />";
} if ($oilqty > 0) {
echo $oilqty." bottles of oil<br />";
} if ($sparkqty > 0) {
echo $sparkqty." spark plugs<br />";
}
}
$totalamount = 0.00; define('TIREPRICE', 100);
define('OILPRICE', 10);
define('SPARKPRICE', 4); $totalamount = $tireqty * TIREPRICE
+ $oilqty * OILPRICE
+ $sparkqty * SPARKPRICE; $totalamount=number_format($totalamount, 2, '.', ' '); echo "<p>Total of order is $".$totalamount."</p>";
echo "<p>Address to ship to is ".$address."</p>"; $outputstring = $date."\t".$tireqty." tires \t".$oilqty." oil\t"
.$sparkqty." spark plugs\t\$".$totalamount
."\t". $address."\n"; // open file for appending
@ $fp = fopen("$DOCUMENT_ROOT/../orders/orders.txt", 'ab'); flock($fp, LOCK_EX); if (!$fp) {
echo "<p><strong> Your order could not be processed at this time.
Please try again later.</strong></p></body></html>";
exit;
} fwrite($fp, $outputstring, strlen($outputstring));
flock($fp, LOCK_UN);
fclose($fp); echo "<p>Order written.</p>";
?>
</body>
</html>
Warning: flock() expects parameter 1 to be resource, boolean given in D:\MyServer\Apache2.2.9\htdocs\study\processorder.php on line 59原函数就是flock($fp,LOCK_EX),我和书上写的一样,然后就是一直报错。高手们能帮忙看看是怎么回事么?谢谢了! 我的代码和12楼的一样,请告诉我应该怎么修改,谢谢了