小弟正是看不懂才来讨教!!!能否给小弟个小小的例子!!!
如
<?php
$filter = '620131';
$handle = fopen("/baofei/today_6201.xd", "r");
$total = 0;
if ($handle) { while (!feof($handle)) { $argn = fgets($handle, 4096); $p = explode("|", trim($argn)); if (empty($filter) || $p[0] == $filter) {
$total += $p[5] > 0 ? $p[8] : (0 + $p[8]);
echo $p[0], "\t", $p[3], "\t", $p[6],"\t", $p[5],"\t", $p[8], " <br/>";
}
}
fclose($handle);
}
echo "合计\t", $total, "\n";
?>这段代码是提供查找一个文本数据库里得所有620131的信息的.
但是这个文本数据还有N多个620101等等等的子数据,不可能每一个信息都要写上这么一段代码吧!!应该能做成函数或者什么形式,让我需要的时候就调用着部分!!!
如
<?php
$filter = '620131';
$handle = fopen("/baofei/today_6201.xd", "r");
$total = 0;
if ($handle) { while (!feof($handle)) { $argn = fgets($handle, 4096); $p = explode("|", trim($argn)); if (empty($filter) || $p[0] == $filter) {
$total += $p[5] > 0 ? $p[8] : (0 + $p[8]);
echo $p[0], "\t", $p[3], "\t", $p[6],"\t", $p[5],"\t", $p[8], " <br/>";
}
}
fclose($handle);
}
echo "合计\t", $total, "\n";
?>这段代码是提供查找一个文本数据库里得所有620131的信息的.
但是这个文本数据还有N多个620101等等等的子数据,不可能每一个信息都要写上这么一段代码吧!!应该能做成函数或者什么形式,让我需要的时候就调用着部分!!!
{
$filter = '620131';
$handle = fopen("/baofei/today_6201.xd", "r");
$total = 0;
if ($handle) { while (!feof($handle)) { $argn = fgets($handle, 4096); $p = explode("|", trim($argn)); if (empty($filter) || $p[0] == $filter) {
$total += $p[5] > 0 ? $p[8] : (0 + $p[8]);
echo $p[0], "\t", $p[3], "\t", $p[6],"\t", $p[5],"\t", $p[8], " <br/>";
}
}
fclose($handle);
}
echo "合计\t", $total, "\n";
}
用的时候
include(conn.php)
conn();//调用函数就可以了jf
{
//$filter = '620131';
$handle = fopen("/baofei/today_6201.xd", "r");
$total = 0;
if ($handle) { while (!feof($handle)) { $argn = fgets($handle, 4096); $p = explode("|", trim($argn)); if (empty($filter) || $p[0] == $filter) {
$total += $p[5] > 0 ? $p[8] : (0 + $p[8]);
echo $p[0], "\t", $p[3], "\t", $p[6],"\t", $p[5],"\t", $p[8], " <br/>";
}
}
fclose($handle);
}
echo "合计\t", $total, "\n";
}
用的时候
include(conn.php)
conn($filter);//调用函数就可以了
//加法函数
function adda($a,$b)
{
$c = $a+$b;
return $c;
}$num = adda(11,222);
echo $num;//输出233
$total = 0;
if ($handle) { while (!feof($handle)) { $argn = fgets($handle, 4096); $p = explode("|", trim($argn)); if (empty($filter) || $p[0] == $filter) {
$total += $p[5] > 0 ? $p[8] : (0 + $p[8]);
echo $p[0], "\t", $p[3], "\t", $p[6],"\t", $p[5],"\t", $p[8], " <br/>";
}
}
fclose($handle);
}
echo "合计\t", $total, "\n";想将这些做成一个函数,然后以$filter ="****"为查找信息!!然后调用上面的操作!!!
完整的代码是$filter ="620101"
handle = fopen("/baofei/today_6201.xd", "r");
$total = 0;
if ($handle) { while (!feof($handle)) { $argn = fgets($handle, 4096); $p = explode("|", trim($argn)); if (empty($filter) || $p[0] == $filter) {
$total += $p[5] > 0 ? $p[8] : (0 + $p[8]);
echo $p[0], "\t", $p[3], "\t", $p[6],"\t", $p[5],"\t", $p[8], " <br/>";
}
}
fclose($handle);
}
echo "合计\t", $total, "\n";
现在如何写函数和在需要时调用,
即要显示today_6201.xd中的620101为标示的的数据!!!620101为例子!!数据中还有620102-620131等很多!!