Program for dynamically publishing news in real time using text files _ PHP Tutorial

Source: Internet
Author: User
Tags newsfile
A program that uses text files to dynamically publish news in real time. The program for dynamically publishing news in real time can automatically arrange the display order according to the release time. News files are composed of text files stored in a specified directory. when there is news, programs that dynamically publish news in real time can automatically sort 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.


News


News






































































Bytes. A news file is composed of text files stored in a specified directory. when there is news, the program...

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. "". $ linktext. "". $ 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 filesArsort ($ 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.