PHP 實用技巧集錦

1) 高速緩存動態(tài)PHP頁面
緩存整個網(wǎng)站,你需要考慮哪些網(wǎng)頁獲得高流量,哪些頁面做一些數(shù)據(jù)庫請求。靜態(tài)HTML頁面不需要緩存,因此有效的緩存對于開發(fā)是很重要的


代碼實例

2 ) 閱讀Excel工作表中PHP
首先準備附件 PHPExcelReader
一、 概述
PHP-ExcelReader 是一個讀取 Excel xsl 文件內(nèi)容的一個 PHP 類。
它的下載網(wǎng)址: http://sourceforge.net/projects/phpexcelreader/
文件名: phpExcelReader.zip
包含兩個必需文件: oleread.inc 、 reader.php 。其它文件是一個應用例子 , 自述文件等
二、 文件使用
首先 , 包含 reader 類文件: require_once " reader.php";
新建一個實例: $xl_reader= new Spreadsheet_Excel_Reader ( );
讀取 Excel 文件信息: $xl_reader->read("filename.xls");
它將導出 Excel 文件中所有可以識別的數(shù)據(jù)存儲在一個對象中。數(shù)據(jù)存儲在 2 個數(shù)組中,目前沒有提供方法 / 函數(shù)訪問這些數(shù)據(jù). 可以像下面這樣簡單的使用數(shù)組名。
sheets 數(shù)組包含了讀取入對象的大量數(shù)據(jù)。它將導出 Excel 文件中所有可以識別的數(shù)據(jù)存儲在一個 2 維數(shù)組中 $xl_reader->sheets[x][y] 。 x 為文檔中的表序號, y 是以下的某個參數(shù) :
numRows -- int -- 表的行數(shù)
例如: $rows = $xl_reader->sheets[0]['numRows']
numCols -- int -- 表的列數(shù)
例如: $cols = $xl_reader->sheets[0]['numCols']
cells -- array -- 表的實際內(nèi)容。是一個 [row][column] 格式的 2 維數(shù)組
例如: $cell_2_4 = $xl_reader->sheets[0]['cells'][2][4] // 行 2, 列 4 中的數(shù)據(jù)
` cellsInfo -- array -- 表格中不同數(shù)據(jù)類型的信息。每個都包含了表格的原始數(shù)據(jù)和類型。這個數(shù)組包含 2 部分: raw -- 表格原始數(shù)據(jù); type -- 數(shù)據(jù)類型。
注:只顯示非文本數(shù)據(jù)信息。
例如:

$cell_info = $xl_reader[0]['cellsInfo'][2][4]
$cell_info['raw'] is the raw data from the cell
$cell_info['type'] is the data type
$xl_reader->sheets

數(shù)組示例:
boundsheets 數(shù)組包含了對象的其它信息,數(shù)組按 workbook 索引。 第二個索引為名稱: $xl_reader->boundsheets[i]['name'] 返回第 i 個表的表名
例如: $sheetname = $xl_reader->boundsheets[0]['name']; // name of the first sheet
$xl_reader-> boundsheets 數(shù)組示例:

(
      [0] => Array
          (
              [name] => Sheet1
              [offset] => 3054
          )
  )```
PHP-ExcelReader 只能支持   BIFF7 ,BIFF8 格式的文件。包括 Excel95 到 Excel2003. 但是不包含 Excel5.0 及之前的版本. 實際上   Excel XP   和 Excel 2003   使用的 BIFF8X 是 BIFF8 格式的一個擴展 . 所有添加的特性可能不被 PHP-ExcelReader. 鎖支持。否則它只能以 Excel XP/2003 文件運行。
**如果出現(xiàn): ****Fatal error: require_once() [function.require]: Failed opening required 'Spreadsheet/Excel/Reader/ OLERead.php ' (include_path='.;\xampp\php\PEAR') in XXXX**

意 思是缺少`Spreadsheet/Excel/Reader/OLERead.php`這個文件。但是確實是沒有這個文件呀!找了找,在excel目錄下發(fā) 現(xiàn)了`oleread.inc`文件,于是將`Spreadsheet/Excel/Reader/OLERead.php`換成 `oleread.inc` 就OK了!
也就是將

require_once 'Spreadsheet/Excel/Reader/OLERead.php';

修改為
`require_once 'oleread.inc';`

即可。
另外,在example.php 中,需要修改
`$data->setOutputEncoding('CP1251');`
為
`$data->setOutputEncoding('CP936');`

不然的話中文將會有問題。
如果是使用繁體的話可以修改為CP950、日文是CP932,具體可參考codepage說明。
還有,其自帶的 jxlrwtest.xls 可能有問題,需要修改example.php中的:
`$data->read(' jxlrwtest.xls ');`
最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容