Closed Thread Icon

Topic awaiting preservation: Php and textfiles (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12161" title="Pages that link to Topic awaiting preservation: Php and textfiles (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Php and textfiles <span class="small">(Page 1 of 1)</span>\

 
OlssonE
Maniac (V) Inmate

From:  Eagleshieldsbay, Sweden
Insane since: Nov 2001

posted posted 04-04-2002 13:50

How do you use an textfile to save info with an ; for example between the post.
What I am asking is how do you make colums and rows in a textfile?

jiblet
Paranoid (IV) Inmate

From: Minneapolis, MN, USA
Insane since: May 2000

posted posted 04-04-2002 14:22

Not sure exactly what you're asking, but here's the PHP commands you will need, other than these you just need to construct the appropriate strings to put in the file:

fopen
fputs
fclose

There are, of course, many other useful file functions, but those are the basics for just editing a simple text file.

-jiblet

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 04-04-2002 14:41

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

OlssonE
Maniac (V) Inmate

From:  Eagleshieldsbay, Sweden
Insane since: Nov 2001

posted posted 04-04-2002 15:18

Ehh...I'm asking for a replacement for a ordinary database. For example this is how it would look in the textfile:

text.txt:
---------------------------------------------
OlssonE~Lunatic~Sweden~2001~Nov
Jibblet~Lunatic~Minneapolis~2000~May
InI~Psycothic~Switzerland~2001~Mars
---------------------------------------------

I want to write and read from this file and put it on a webpage

----------------------------------------------------------------------------------------

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 04-04-2002 15:21

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

deethree
Obsessive-Compulsive (I) Inmate

From: An igloo up north
Insane since: Mar 2002

posted posted 04-04-2002 15:58

Wouldn't explode() work in his situation as well?

Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 04-04-2002 16:02

explode() will work fine for that.

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 04-04-2002 17:13

Here's a real quick list I wrote once. It's really bad and I can think of about 10 ways to change it but all the basics are there.

The form just asks for a first name last name email and phone
This is a "one-page" form where the form and the process are all one php page
I used double semi-colons (; for my seperator.
I could have used something else but I was doing this really quick and it worked.
<?
// instatiate the package of data
$daPackage = "";

// since it's a one page form let's check to see if it's submitted.
if (isset($submitted)) {
// create the package
$daPackage .= $fname.";;";
$daPackage .= $lname.";;";
$daPackage .= $email.";;";
$daPackage .= $phone.";;";
// open the text file
$fp = fopen("pololist.inc", "a+");
$daPackage = trim($daPackage);
// I should have checked if something was submitted earlier but oh well.
if ($daPackage != ";;;;;;;;") {
//put a line break at the end
$daPackage .= "\n";
// write to the file
fwrite($fp, "$daPackage");
}
fclose($fp);
}
//reading the file
$list = "";
// open the file for reading.
$contents = file("pololist.inc");
// I'm reading line by line (PHP does this autmomatically) so this basically says "read each line as $var"
foreach ($contents as $var) {
// create an array, of each item in between double semi-colons.
$daArray = explode(";;",$var);
if ($daArray) {
//create the HTML output
$list .= "<tr><td>".$daArray[0]." ".$daArray[1]."</td><td>".$daArray[2]."</td><td>".$daArray[3]."</td></tr>";
}
}

Later on I echo the $list var.

you can see this and play with it here http://www.bitdamaged.com/bacpolo

I put this up and it was never really used.

?>



.:[ The Tao of Steve ]:.
Be Desireless
Be Excellent
Be Gone
...................................

butcher
Paranoid (IV) Inmate

From: New Jersey, USA
Insane since: Oct 2000

posted posted 04-04-2002 17:40

You could also use fgetcsv. It has worked very nicely for me in the past.

You use it something like this to break it down for use in your page:

$filename = "show_info.csv";
$fp = @fopen($filename, "r") or die("Couldn't open file");
while($row = @<B>fgetcsv($fp, 1000, "

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 04-04-2002 17:58

Jeez I love PHP!

I wish I found that earlier!



.:[ The Tao of Steve ]:.
Be Desireless
Be Excellent
Be Gone
...................................

« BackwardsOnwards »

Show Forum Drop Down Menu