-
I could probably find it one the 'net, but it's late, I'm tired and I've to work tomorrow :p
This belongs in the Beginner's Corner, I think, but I'll post it here anyway.
What's the most common way to use text files together with PHP? I want to use it for a links page and later maybe more.
Thanks for your time!
-
Dear Elledan...
There are two ways, one, is just parse the form data and save it together with the HTML you want to go with the links, for example...
The form returns:
$linkname = "Yahoo";
$linkurl = "http://www.yahoo.com/";
Then, you save the file with
<?php
$oldfile = file ("path/to/file.txt");
$towrite = "<a href=\"$linkurl\">$linkname";
for ($i = 0; $i <= count ($oldfile); $i++){
$towrite .= "$oldfile[$i]";
}
$fp1 = fopen ("path/to/file.txt", "w");
fputs ($fp, $towrite);
fclose($fp1);
?>
The second type is to build your own database format, and I've been using this method.
The .txt file might look like...
|Yahoo|http://www.yahoo.com/|
|SitePoint|http://www.sitepoint.com/|
|CCN|http://www.ichacha.net/|
... try figuring out the code yourself, it's much or less the same as the one on top.
-
Thanks for your help! I think I got a basic idea of how to do it now :)
-