Hi
I'm new to PHP and programming but have managed to make an article creation script. This script indexes and formats user submitted articles. It writes links to articles in a text file, the links are preformatted as list items.
I want to read the first 5 links from this file, strip the formatting and then display them on my main page.
The text file is in this format...
I made the following to extract and reformat the first 5 links. It does not work and I am stuck!!
Any help would be appreciated, I think I am going along the wrong lines with this
Cheers
Mike
I'm new to PHP and programming but have managed to make an article creation script. This script indexes and formats user submitted articles. It writes links to articles in a text file, the links are preformatted as list items.
I want to read the first 5 links from this file, strip the formatting and then display them on my main page.
The text file is in this format...
Code:
<li><a href="Sep-06-213155.php">Test Article</a><br /><span class="redtext"><b>Mike</b></span> <span class="greytext">6th September 2001</span></li>
I made the following to extract and reformat the first 5 links. It does not work and I am stuck!!
Code:
<?
#open file
$myfile = "/PATH/TO/data.txt";
#number of files plus one
$maxlatest =4;
#- Article links file
if(file_exists($myfile)){
$fh = fopen($myfile, "r");
$old_news = fread($fh, filesize($myfile));
fclose($fh);
}
#- get first five article links
$articles = explode("</li>", $old_news);
$articles = str_replace("<li>","",$articles);
$articles = str_replace("<br />"," by ",$articles);
$articles = str_replace("2001</span>","2001</span><br />",$articles);
$i=0;
foreach ($articles as $article){
if(count($articles)>$i){
if($maxlatest >= $i++){
print $article;
}
}
}
?>
Any help would be appreciated, I think I am going along the wrong lines with this
Cheers
Mike