Dynamic real-time publishing of news programs with text files _php Tutorial

Source: Internet
Author: User
Tags newsfile
Dynamic real-time publishing of news programs, you can automatically arrange the display order according to the release time. A news file consists of a text file stored in a specified directory, and when there is news, the program automatically displays it and arranges it at the very beginning of the page.


<title>News</title>


News







































































http://www.bkjia.com/PHPjc/316336.html www.bkjia.com true http://www.bkjia.com/PHPjc/316336.html techarticle Dynamic Real-time publishing of news programs, you can automatically arrange the display order according to the release time. The news file consists of a text file stored in the specified directory, and when there is news, the program ...

  • Include (' locationfilename.php ');function Createur1 ($text) {In the news text file so insert your link${http://mysite.ch}or ${http://mysite.ch|my homepage in}Start working with text files section$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);}else{$linktext = $a;}$s = $s. "". $linktext. "". $b;}}return ($s);}Edit your news file storage directory hereRemember that the news file must be a text file$newspath = "/home/htdocs/test/new/";Set array$newsfile =array ();Set up a directory handle$HD =dir ($newspath);Get all the files and store them in an arraywhile ($filename = $hd->read ()) {$s =strtolower ($filename);if (Strstr ($s, ". txt")) {Detect Latest modification Date$lastchanged =filemtime ($newspath. $filename);$newsfile [$filename]= $lastchanged;}}File sortArsort ($newsfile);Output filefor (Reset ($newsfile); $key =key ($newsfile); next ($newsfile)) {$fa =file ($newspath. $key);$n =count ($FA);Print " "; } $HD->close ();?>
    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 "

    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.