ninevolt1 Posted August 14, 2009 Share Posted August 14, 2009 Is there any way to modify the below script to get the last five articles? Right now as it is, it opens an html file and displays on my web page the first 5 articles. I have a need where I will want it to display the last 5 articles. The html file is one huge file with many news articles in it. The script knows where each article starts by looking for the "<!--ARTICLE-->" before each article. Any help will be greatly appreciated. <?php require('news_manager/dconfig.php'); $filename = "news_manager/camera_summary2.html"; #- open article summaries if(file_exists($filename)){ $fh = fopen($filename, "r"); $old_news = fread($fh, filesize($filename)); fclose($fh); } #- get first five article $articles = explode("<!--ARTICLE-->", $old_news); $i=0; foreach ( $articles as $article ){ if(count($articles)>$i){ if($max_latest >= $i++){ print $article; } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/170214-need-help-modify-a-script-to-pull-articles-from-a-file/ Share on other sites More sharing options...
infiniteacuity Posted August 14, 2009 Share Posted August 14, 2009 You can try loading them into an array, reversing it, and only displaying the first 5 Quote Link to comment https://forums.phpfreaks.com/topic/170214-need-help-modify-a-script-to-pull-articles-from-a-file/#findComment-898087 Share on other sites More sharing options...
ninevolt1 Posted August 14, 2009 Author Share Posted August 14, 2009 You can try loading them into an array, reversing it, and only displaying the first 5 I don't know PHP very well. Would that be a few lines of code or many pages of code? Quote Link to comment https://forums.phpfreaks.com/topic/170214-need-help-modify-a-script-to-pull-articles-from-a-file/#findComment-898168 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.