Jump to content

PHP file read and echo


gsencan

Recommended Posts

I have a .txt like this

 

italian,www.mydomain.com/image/italian.gif,www.mydomain.com/nation/italian.php,201108060922  /=>this is date

english,www.mydomain.com/image/english.gif,www.mydomain.com/nation/english.php,201108070923

arabic,www.mydomain.com/image/arabic.gif,www.mydomain.com/nation/arabic.php,201108080924

.

.

.

.

goes on

 

i want to show most recent 20 images by date (which exist in each line )        /And in another page i want to show most recent 21 to 40 

And image name on images(italian or english etc.)  with image place which i put like www.mydomain.com/image/italian.gif

so when u click an image you will go to the  webpage which it links to

 

I found many codes but none of them are capable of this... any suggestions??  (not an easy way i know)

Link to comment
Share on other sites

well, here's a handout... not the only way to do it, not even the best, but probably the easiest for you to understand. I left the easy part for you to solve (adding the actual images and creating the link)

 

<?php 
// read file
$file = file_get_contents('YOUR_FILE_NAME_HERE.txt');
// break file into lines
$lines = explode("\n",$file);
// create empty array to hold values
$myArray = array();
// loop through each line
foreach($lines as $line){
// separate fields
$fields = explode(",",$line);
// remove date from array and use as key
$date = array_pop($fields);
$myArray[$date] = $fields;
}
// sort array by keys (date)
ksort($myArray);
// initialize counter
$count = 0;
// loop through result and display
foreach($myArray as $date => $values){
// limit to 20
if($count >= 20) break;
// show data
echo "<br>LANGUAGE: ".$values[0];
echo "<br>IMAGE: ".$values[1];
echo "<br>LINK: ".$values[2];
echo "<br>DATE: ".$date;
echo "<hr>";
// increment counter
$count++;
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.