Jump to content

Recommended Posts

Edit: Fixed

 

Used list and explode to extract data.

 

hello.

 

I am trying to figure out how to make a script that reads from a .txt file and displays data from it, liek a database.

 

the values is stored liek this:

440408,TH0rn,258,1,68,2853
250983,m0f0kiss,0,1,80,1072
270181,PsykoNinja,8,1,67,3103
539930,iajamo,127,1,73,2216
332802,luk3y,14,1,67,3104

 

Any help in doing this?

 

My best attempt is:

<?php
$get_name = 'DeathStar0'; 
echo '<table><tr><th>Name</th><th>x</th><th>y</th><th>Points</th></tr>';
$lines = gzfile('http://thedomain.com/file.txt.gz');
if(!is_array($lines)) die("File could not be opened"); 
foreach($lines as $line) {
list($id, $name,$x, $y, $player, $points, $rank) = explode(',', $line);
$name = urldecode($name);
$name = addslashes($name);
if ($name = $get_name){
echo '<tr><td>'.$name.'</td><td>'.$x.'</td><td>'.$y.'</td><td>'.$points.'</td></tr>';
exit;

}
}
echo '</table';
?>[/code[

Link to comment
https://forums.phpfreaks.com/topic/53913-solved-txt-database/
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.