0
我有一個php代碼,目前從txt文件創建一個html文件,並更新每兩個小時在我的網站上。我想將其轉換爲數據表。有沒有簡單的方法鏈接到使用jQuery,數據表和PHP的txt文件?使用數據表和php
這是我提出:http://live.datatables.net/eduvin/edit#javascript,html,live
,我使用的是一種將使用PHP爲HTML一個txt文件的文件。 PHP每兩小時在服務器上更新一次。我想用jQuery數據表替換所有這些,並每兩個小時更新一次。我使用的更新程序是Windows Server 2003中的Windows任務計劃程序。這可能嗎?如果是的話,那麼最好的辦法是什麼。
這是我的PHP代碼:
<?php
set_time_limit(0);
function csv_split($line,$delim=',',$removeQuotes=true) {
#$line: the csv line to be split
#$delim: the delimiter to split by
#$removeQuotes: if this is false, the quotation marks won't be removed from the fields
$fields = array();
$fldCount = 0;
$inQuotes = false;
for ($i = 0; $i < strlen($line); $i++) {
if (!isset($fields[$fldCount])) $fields[$fldCount] = "";
$tmp = substr($line,$i,strlen($delim));
if ($tmp === $delim && !$inQuotes) {
$fldCount++;
$i += strlen($delim)-1;
} else if ($fields[$fldCount] == "" && $line[$i] == '"' && !$inQuotes) {
if (!$removeQuotes) $fields[$fldCount] .= $line[$i];
$inQuotes = true;
} else if ($line[$i] == '"') {
if ($line[$i+1] == '"') {
$i++;
$fields[$fldCount] .= $line[$i];
} else {
if (!$removeQuotes) $fields[$fldCount] .= $line[$i];
$inQuotes = false;
}
} else {
$fields[$fldCount] .= $line[$i];
}
}
return $fields;
}
$html_body = 'HTML goes here'
$fp=fopen("csv/inventory4.html",'w');
$write=fputs($fp,$html_body,strlen($html_body));
$i=0;
$content = file("webinvt.txt");
foreach($content as $line)
{
$l=csv_split($line);
if(!strstr($l[11],"SET"))
{
if($i==10)
{
$tmp = '</table>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0"> <tbody><tr>
';
$write=fputs($fp,$tmp,strlen($tmp));
$i=0;
}
$onhand = (int)$l[15];
$committed = (int)$l[16];
$avail = $onhand - $committed;
$wcdate = substr($l[23],4);
$eastdate = substr($l[19],4);
if(strstr($l[1],"DISC"))
{
$html_body ='<tr style="color:#FF0000 ">
<td width="12%" >'.$l[0].'</td>
<td width="30%" >'.$l[1].'</td>
<td width="8%" >'.$l[12].'</td>
<td width="8%" >'.$avail.'</td>
<td width="8%" >'.$l[17].'</td>
<td width="8%" >'.$l[18].'</td>
<td width="8%" >'.$eastdate.'</td>
<td width="8%" >'.$l[21].'</td>
<td width="8%" >'.$l[22].'</td>
<td width="8%" >'.$wcdate.'</td>
</tr>';
}
else
{
$html_body ='<tr>
<td width="12%" >'.$l[0].'</td>
<td width="30%" >'.$l[1].'</td>
<td width="8%" >'.$l[12].'</td>
<td width="8%" >'.$avail.'</td>
<td width="8%" >'.$l[17].'</td>
<td width="8%" >'.$l[18].'</td>
<td width="8%" >'.$eastdate.'</td>
<td width="8%" >'.$l[21].'</td>
<td width="8%" >'.$l[22].'</td>
<td width="8%" >'.$wcdate.'</td>
</tr>
';
}
$write=fputs($fp,$html_body,strlen($html_body));
$i++;
}
}
$html_body='<tr>
<td scope="col"></td>
<td scope="col"></td>
<td scope="col"></td>
<td scope="col"></td>
<td scope="col"></td>
<td scope="col"></td>
<td scope="col"></td>
<td scope="col"></td>
<td scope="col"></td>
<td scope="col"></td>
<td scope="col"></td>
</tr>
</table>
</body>
</html>';
$write=fputs($fp,$html_body,strlen($html_body));
fclose($fp);
?>
這就是我的想法,但我不知道如何去掉txt文件,因爲它包含了我所有的數據。 – user458474
你有沒有例子?它應該很容易。 –
我加了php代碼看一下 – user458474