Dynamic and real-time publishing of news Program The display order is automatically arranged according to the release time. A news file is a text file stored in a specified directory. When there is news, the program will automatically display it and arrange it in the first part of the page.
<HTML>
<Head>
<Title> News </title>
</Head>
<Body bfcolor = "# ffffff">
<H1> News <Div aligh = "center">
<Table border = "0" cellspacing = "5" cellpadding = "10" width = "90%" bgcolor = "# e0e0e0">
<? PHP
Include ('locationfilename. php ');
Function createur1 ($ text ){
// Insert your link in the text file of news
// $ {Http://mysite.ch}
// Or $ {http://mysite.ch | my homepage in}
// Start to process text files
$ S = $ text;
$ A = strstr ($ S, '$ {');
If ($ ){
$ B = strstr ($ ,'}');
If ($ B ){
$ LA = strlen ($ A); $ ls = strlen ($ S );
$ S = substr ($ S, 0, $ LS-$ la );
$ A = substr ($ A, 2 );
$ LB = strlen ($ B); $ LA = strlen ($ );
$ 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 );
}
Else {
$ Linktext = $;
}
$ S = $ S. "<a href =" ". $ A." ">". $ linktext. "</a>". $ B;
}
}
Return ($ S );
}
// Modify the news file storage directory here
// Remember, the news file must be a text file
$ Newspath = "/home/htdocs/test/New /";
// Set the Array
$ Newsfile = array ();
// Set the directory handle
$ Hd = Dir ($ newspath );
// Obtain all objects and store them in an array.
While ($ filename = $ HD-> Read ()){
$ S = strtolower ($ filename );
If (strstr ($ S, ". txt ")){
// Check the latest modification date
$ Lastchanged = filemtime ($ newspath. $ filename );
$ Newsfile [$ filename] = $ lastchanged;
}
}
// Sort files
Arsort ($ newsfile );
// Output file
For (reset ($ newsfile); $ key = Key ($ newsfile); next ($ newsfile )){
$ Fa = file ($ newspath. $ key );
$ N = count ($ FA );
Print "<tr> <TD> N ";
Print "<B> ". date ("D. m. y-H: I: s ", $ newsfile [$ key]). "</B> <br> N ";
For ($ I = 0; $ I <$ N; $ I = $ I + 1 ){
$ S = chop ($ Fa [$ I]);
$ S = htmlspecialchars ($ S );
$ S = createur1 ($ S );
Print $ S. "<br> N ";
}
Print "</TD> </tr> ";
}
$ HD-> close ();
?>
</Body>
</Html>