我想從一個PHP文件中包含一個函數到另一個函數中,並使用帶有參數的函數並獲取返回值。一切都很好,直到我運行功能,PHP死亡。我怎樣才能解決這個問題?PHP - 爲什麼包含來自其他文件的函數失敗?
timestamp_reader.php:
<?php
function get_time($timestamp){
$year = substr($timestamp, 0, 4);
$month = substr($timestamp, 4, 2);
if(substr($month, 0, 1) == "0")
$month = substr($month, 1, 1);
$day = substr($timestamp, 6, 2);
if(substr($day, 0, 1) == "0")
$day = substr($day, 1, 1);
$hour = substr($timestamp, 8, 2);
if(substr($hour, 0, 1) == "0")
$hour = substr($hour, 1, 1);
$hour = intval($hour);
if($hour > 12){
$hour = $hour - 12;
$pm = true;
}else $pm = false;
$minute = substr($timestamp, 10, 2);
if(substr($day, 0, 1) == "0")
$day = substr($day, 1, 1);
if($pm) $minute .= " PM";
else $minute .= " AM";
return $month . "/" . $day . "/" . $year . " " . $hour . ":" . $minute;
}
?>
而且我希望獲得此功能的文件(注意,這是在不同的目錄):
...some PHP code before this...
include "/project/includes/timestamp_reader.php";
while($row=mysql_fetch_array($result)){
$msg = $row['message'];
$timestamp = $row['timestamp'];
$time = get_time($timestamp);
echo "<p><center>" . $time . " " . $msg . "</center></p>";
}
我想這個數字並將其用於各種功能,所以如果可能的話,我不必每次都輸入它們。另外,我需要類似的東西來創建項目範圍的變量。
無論如何,感謝您的幫助!
你會得到什麼錯誤? – Niko
什麼是錯誤信息? –
看起來像使用'date()'和'strtotime()'在這裏會是一個更好的主意。 –