我的一亩三分地 我就喜欢!
13fen  设为主页
 收藏本站
 
当前位置: > 一亩三分地:首页 > 网络学院 > 网络编程 > PHP专区 > php安装/入门 > 自动发布新闻的php代码
热门文章排行
热门文章排行 检查email地址格式的代码(01-11)
PHP操作文件问答(01-11)
PHP安装攻略:安装并配置PHP(10-23)
PHP的十个高级技巧 4(10-23)
PHP控制语句(10-12)
精采文章排行
精采文章排行 PHP连接MYSQL的两种方法(11-15)
PHP和MySQL开发的8个技巧(10-23)
PHP安装攻略:安装并配置PHP(10-23)
php+mysql扎实个人基本功(10-23)
PHP编程常用技巧四则(10-23)
技术专题推荐
网管论坛交流
 

自动发布新闻的php代码 

作者:佚名   来源:本站教程   点击:   日期:2007-01-11

新闻文件以文本文件.txt的格式存放在一个固定的目录下,新闻的发布可以自动完成。

该过程由两部分组成:

第一是新闻的显示,由shownews.php脚本实现,代码如下:
〈table border="0" width="90%"〉
〈?php
//在新闻文件中的第一行放新闻的标题
//新闻文件必须是文本文件(.txt)
$newspath = "./news/"; // 修改新闻文件存放的目录
$newsfile = array();
$hd = dir($newspath);
while( $filename = $hd-〉read() ) {
$s=strtolower($filename);
if (strstr($s,".txt")) {
$lastchanged=filemtime($newspath.$filename);
$newsfile[$filename] = $lastchanged;
}
}
arsort($newsfile);
for(reset($newsfile); $key = key($newsfile); next($newsfile)) {
print "〈tr〉〈td〉n";
$fa = file($newspath.$key);
$s=trim($fa[0]);
$s=htmlspecialchars($s);
$lk=strlen($key);
$a=substr($key,0,$lk-4);
$s="〈a href="./pubnews.php?id=".$a."" target=_blank〉".$s."〈/a〉";
print $s." n";
print "(".date("Y年m月d日 - H:i:s",$newsfile[$key]).")
n";
print "〈/td〉〈/tr〉";
}
$hd-〉close();
?〉
〈/table〉

在显示新闻的地方放入代码:
〈?php
require "./shownews.php";
?〉

第二部分为新闻的发布,由pupnews.php脚本实现,代码如下:
〈?php
if ($id=="")
{
Header("Location: ./shownews.php");
}
?〉
〈html〉
〈head〉
〈meta content="chenqiang" name=Author〉
〈?php
$filename="./news/".$id.".txt";
$fa=file($filename);
$n=count($fa);
$s=trim($fa[0]);
$s=htmlspecialchars($s);
$t=" - news by waterwall";
print "〈title〉".$s.$t."〈/title〉n";
?〉
〈/head〉
〈body〉
〈?php
//输出文本标题
print "〈blockquote〉n";
print "〈b〉〈center〉".$s."n";
print "〈/center〉〈/b〉
〈p〉n";
//输出文本正文
for ($i=1;$i〈$n;$i+=1)
{
$s=chop($fa[$i]);
$s=htmlspecialchars($s);
$s=trim($s);
print " ".$s."
n";
}
print "〈/p〉〈/blockquote〉n";
?〉
〈/body〉
〈/html〉

用数据库也可实现,这只是文件形式的实现方式。

文章评论】 【收藏本文】 【推荐好友】 【打印本文】 【论坛讨论

   相关文章:
·将OICQ数据转成MYSQL数据 ·用PHP实现ODBC数据分页显示一例
·php生成WAP页面 ·PHP与Javascript的两种交互方式
·PHP+Javascript模拟Matrix画面 ·WHOIS类的修改版

   文章评论:(条)
  
 请留名: 匿名评论   点击查看所有评论 网管论坛
 

  责任编辑:一分  声明:刊登此文章是为了传递更多信息,文章内容仅供参考,转载请注明出处。