The _php foundation of the program of Dynamic real-time publishing news with text file

Source: Internet
Author: User
Tags newsfile strlen
Dynamic real-time release of news programs, according to the release time, automatically arrange the display order. News files are composed of text files stored in the specified directory, and when there is news, the program automatically displays them and arranges them at the beginning of the page.
<title>News</title>
<body bfcolor= "#ffffff" >
<div aligh= "center" >
<table border= "0" cellspacing= "5" cellpadding= "ten" width= "90%" bgcolor= "#e0e0e0" >

<?php

Include (' locationfilename.php ');

function Createur1 ($text) {
The news text file in this way inserts your link
${http://mysite.ch}
or ${http://mysite.ch|my homepage in}
Start working with the text file 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. " <a href= "". $a. "" > ". $linktext." </a> ". $b;
}
}

return ($s);
}

Here to modify your news file storage directory
Remember, the news file must be a text file
$newspath = "/home/htdocs/test/new/";

Set array
$newsfile =array ();

Set up table of contents handles
$HD =dir ($newspath);

Get all the files and store them in an array
while ($filename = $hd->read ()) {
$s =strtolower ($filename);
if (Strstr ($s, ". txt")) {
Detect Latest Modified Date
$lastchanged =filemtime ($newspath. $filename);
$newsfile [$filename]= $lastchanged;
}
}

sorting 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>

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.