Home  >  Article  >  Backend Development  >  A program to publish dynamic news in real time using text files_PHP tutorial

A program to publish dynamic news in real time using text files_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 16:03:21857browse

A program for dynamically publishing news in real time, which can automatically arrange the display sequence according to the release time. News files are text files stored in the specified directory. When there is news, the program will automatically display it and arrange it at the beginning of the page.


News


News






include('locationfilename.php');

function createur1($text){
/ /Insert your link into the news text file like this
//${http://mysite.ch}
//Or ${http://mysite.ch|My homepage in}
//Start processing the text file part
$s=$text;
$a=strstr($s,'${');
if ($a){
$b=strstr( $a,'}');
if ($b){
$la=strlen($a); $ls=strlen($s);
$s=substr($s,0 ,$ls-$la);
$a=substr($a,2);
$lb=strlen($b); $la=strlen($a);
$a=substr ($a,0,$la-$lb); $b=substr($b,1);
$ta=strstr($a,"|");
if($ta){
$la=strlen($a); $lt=strlen($ta);
$linktext=substr($a,$la-$lt+1);
$a=substr($a ,0,$la-$lt);
                                                          $a."">".$linktext."".$b;
}
}

return($s);
}

//Modify your news file storage directory here
//Remember, news files must be text files
$newspath="/home/htdocs/test/new/";

//Set the array
$newsfile=array();

//Set the directory handle
$hd=dir($newspath);

//Get all files, And store it in the array
while($filename=$hd->read() ){
$s=strtolower($filename);
if (strstr($s,".txt ")){
//Detect the latest modification date
$lastchanged=filemtime($newspath.$filename);
$newsfile[$filename]=$lastchanged;
}
}

//File sorting
arsort($newsfile);
//Output file
for(reset($newsfile); $key=key($newsfile); next($newsfile) ){
$fa=file($newspath.$key);
$n=count($fa);
print "";
}
$hd- >close();

?>


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/316336.htmlTechArticleA program for dynamically publishing news in real time, which can automatically arrange the display order according to the release time. News files are text files stored in the specified directory. When there is news, the program...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
n";
print " ".date("d.m.Y - H:i:s",$newsfile[$key])."
n";
for($i=0; $ i<$n; $i=$i+1){
$s=chop($fa[$i]);
$s=htmlspecialchars($s);
$s=createur1( $s);
print $s."
n";
}
print "