A program for dynamically publishing news in real time using text files

Source: Internet
Author: User
Tags newsfile

The Program for dynamically publishing news in real time can automatically arrange the display order 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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.