肥健的PHP歷程

呵! 呢度係肥健建立o既. 目的係幫我記下日常編寫PHP時O既問題同埋心得. 為目標而加油吧!

Friday, May 02, 2008

久未露面的php blog

哈呵~~勁耐無update 呢度. 近來有d野執下...
話說朋友申請左個hosting有PHP但無MySQL, 正常來說係非常pk的事. 但改不了, 唯有試試用programming 改:
將原先入MySQL的資料修改一下便可以了.幸虧我用左array 0黎pass data(乜仲有其他咩?), OK~而家只係搞file IO:
$filename=sprintf('../data/'.date('Ym',$date).'.dat');
if (file_exists($filename))
{

$handle=fopen($filename,'r');

if ($handle)
{
while(!feof($handle))
{
foreach (split(',',fgets($handle)) as $booking)
{
if ($booking!='')
{
$entry[substr($booking,-1)][substr($booking,0,2)]='';
}
}
}

}
fclose($handle);
}
呢個係read, file_exist睇下file 存唔存在, 有則read入 entry呢一個array入面,讀入data後以comma分開data, 再用substr將資料分開2部份用array盛著,0黎多個寫野0既:

$handle=fopen('../data/'.$date.'.dat','w');

if (count($entry)>0)
{
foreach ($entry as $villas => $nouse)
{
foreach($entry[$villas] as $date =>$nouse2)
fputs($handle,sprintf("%02d-%d,",$date,$villas));
}
}

foreach ($insertdate as $date)
fputs($handle,sprintf('%02d-%s,',$date,$villa));

fclose($handle);

將個file open的attributes改為a,意改apped,再用foreach將array內的數值 fputs返入去.呢度唔駛用file_exist做驗証, 因為無呢個file佢係會自己開0既.

家陣度緊麻煩事...

0 Comments:

Post a Comment

<< Home