请教各位大虾一个小问题!!!急!!!

kbr1984 2008-12-25 09:35:44
小弟有一段PHP小代码
<?php
$filter = '620107';
$handle = fopen("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]);
}
}
fclose($handle);
}
echo "\t", $total, "\n";
?>
现在小弟想在一个HTML主页中的一个位置上直接显示这段PHP的运行结果请问各位大虾小虾如何实现!!!!!!
...全文
104 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
hittlle 2008-12-25
  • 打赏
  • 举报
回复
php代码和HTML可以混合在一起;要实现你所说的要求,可以这样做
<html>
<head></head>
<body>
<?php
$filter = '620107';
$handle = fopen("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]);
}
}
fclose($handle);
}
?>
<p><?php echo $total; ?></p>
</body>
</html>
kbr1984 2008-12-25
  • 打赏
  • 举报
回复
有什么脚本调用的示例嘛!!参考下!!小弟新手一名!!!
kbr1984 2008-12-25
  • 打赏
  • 举报
回复
如何使用脚本调用啊!!!
cyr11 2008-12-25
  • 打赏
  • 举报
回复
静态页面上用不来php代码的
你可以先写好放在一个aa.php页面
在通过<iframe
或脚本调用
kbr1984 2008-12-25
  • 打赏
  • 举报
回复
<?php
function getTxt(){
$filter = '620107';
$handle = fopen("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]);
}
}
fclose($handle);
}
return $total;
}

?>
这样写连正常显示都没有了!!
kbr1984 2008-12-25
  • 打赏
  • 举报
回复
照楼上的做了不行啊!!!!!郁闷急急急!!!求知道的解决下!!!!!这段PHP运行结果是个数字!!我要把这个数字直接显示到主页的一个表中!!!!!!
penglewen 2008-12-25
  • 打赏
  • 举报
回复
<?php
function getTxt(){
$filter = '620107';
$handle = fopen("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]);
}
}
fclose($handle);
}
return $total;
}

?>
写个成函数形式吧,在你要插入的位置直接
<?PHP echo getTxt();?>
kbr1984 2008-12-25
  • 打赏
  • 举报
回复
可以显示!!!是想在一个主页中一个的地方直接插入显示!!
xiaolei1982 2008-12-25
  • 打赏
  • 举报
回复
什么意思?不明白怎么你显示不出来吗?
cgisir 2008-12-25
  • 打赏
  • 举报
回复
把你这段代码写到一个单独的PHP文件
然后最后句这样改下
echo "document.write('\t", $total, "\n');";

在你的HTML页面要显示的地方这样引用你的那个PHP页
<script type="text/javascript" src="myecho.php"></script>
程序猿之殇 2008-12-25
  • 打赏
  • 举报
回复
将这段程序保存为xxx.php
在HTML主页的某个地方,
<?php
echo file_getc_contents("xxx.php");
?>
kbr1984 2008-12-25
  • 打赏
  • 举报
回复
高手!大哥们快来看看啊!!!
wujiajia1989 2008-12-25
  • 打赏
  • 举报
回复
kbr1984 2008-12-25
  • 打赏
  • 举报
回复
谢谢大家!!!结贴

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧