日期:2014-05-17 浏览次数:20470 次
common.php
<?php
public static function readTabFile($fileName)
{
if (!file_exists($fileName))
{
die("<b>404 File not found!</b>");
}
$handle = fopen($fileName, 'rb');
$contents = fread($handle, filesize ($fileName));
//iconv("UTF-8","GBK", $contents);
if(ord($contents) == 0xEF)
{
$contents = substr($contents, 4);
}
$rows = explode("\r\n", $contents);
fclose($handle);
$ret;
$colNames = null;
for($i = 0; $i < count($rows); $i++)
{
$row = $rows[$i];
if(!empty($row) && $row != "" && substr($row, 0, 1) != "#")
{
$col = explode("\t", $row);
if(empty($colNames) || $colNames == null)
$colNames = $col;
else
{
$item;
$itemId = (int)$col[0];
if(empty($itemId))
{
die("...");
}
for($j = 0; $j < count($col); $j++)
{
$value = $col[$j];
$item[$colNames[$j]] = $value;
}
$ret[$itemId] = $item;
}
}
}
return $ret;
}
?>
test.php
<?php
$dir = "../goods.tab";
$table = Common::readTabFile($dir);
?>
<script>
var goodsTb = new Array();
<?php
foreach($table as $key => $value)
{
echo "goodsTb[".$value["id"]."]=\"".iconv("GBK","UTF-8", $value["sz_name"])."\";";
}
?>
function checkNum(i)
{
var sle_obj = document.getElementById('valueType' + i);
var index = sle_obj.selectedIndex;
var valueType = sle_obj.options[index].value;
var num_obj = document.getElementById('count' + i);
if(valueType == -1)
{
alert('请选择道具类型!');
}
if(num_obj.value > 500)