TCH-Thomas Posted May 3, 2004 Posted May 3, 2004 I am trying to figure out a way that would make Jessica (Marve) able to update atleast parts of her site by herself. A few days ago i found this script on a php site ><? $filen = file('namnsdag.txt'); echo "".$filen[date('z')+1]; ?> What it does is that it updates one line on her site every midnight. Now what i would like to do is to place this or something similar on other places on the site so that Jessica can just upload a text file and the text in that will show up on site, but not that it changes or disappear each midnight. I know another way to do this (with a js-file) thanks to TCH-Don but it would require Jessica to insert and things like that, which she would hate to learn . I tried to insert the above code with another txt.file it could refer to, but nope it didnt work. Quote
scotttyz Posted May 3, 2004 Posted May 3, 2004 (if I am guessing right) You are trying to have a way for someone to add text, like a message, to the site. How much formatting are you concerned with? This could be as simple as having a text file that php opens, reads the info into an array and then runs a FOR loop to print out each line in a message. There should be plenty of pre-made scripts that you could use for this. Check out http://www.hotscripts.com/PHP/Scripts_and_...hing/index.html http://php.resourceindex.com/Complete_Scri...tent_Retrieval/ http://php.resourceindex.com/Complete_Scri...ge_Communities/ http://php.resourceindex.com/Complete_Scri...eb_Page_Design/ you should be able to find something in those that will do what you are looking for Rock Sign Quote
TCH-Thomas Posted May 3, 2004 Author Posted May 3, 2004 First, Thanks scotttyz I went through those pages and there was 100´s scripts, most didnt do what i wanted. But i started to play around with one of them and found out that ><?php include("test.txt"); ?> will do what i want, if i skip formatting. I just recently started to play around with php, and my knowledge so far is as near to zero as it can be. The formatting part is not needed for now, Jessica will just have to live that she only will be updating the body texts. Quote
scotttyz Posted May 3, 2004 Posted May 3, 2004 No problem And if you were to have each new comment added on a new line in the text file you could use the following to make each of the text files lines appear as seperate lines in HTML (adding the <br>'s for you) modified from htpasswd.class.php this willl read the file into a variable >// set up variables $filename = "test.txt"; $SplitContents = array(); // let see if we can read $ReadFile = fopen( $filename, "r" ); // if not empty then lets do something with the file if(empty($ReadFile)) { Print("File is empty, Danger Will Robinson"); exit; } //make variable and put in contents $contents = fread( $ReadFile, filesize( $filename ) ); fclose( $ReadFile ); // this will make each line in the text file apear as an array element $SplitContents = split("\n",$contents); and then you could print it out like..... >//set up to move thru each array element for($count=0;$count<count($SplitContents);$count++) // print out the current line {print $SplitContents[$count] . "<br> <br>";} I have not "run" the code but it should work. You could make an easy PHP page to add a new line to the text file using a form and something like $AddThis = $FormFieldName . "\r\n"; $AppendFile = fopen($filename, "a"); fputs($AppendFile, $AddThis); fclose($AppendFile); you would need to have 777 i think for the text file (unix permissions) but you have a simple form (password protected??) that the user could just type in some text, click submit and it will be on the next line in the text file. Quote
TCH-Thomas Posted May 3, 2004 Author Posted May 3, 2004 Ok, thanks scotttyz. I think i understand all that. Will have a closer look at it tomorrow when im more awake. Its soon midnight here, so im off to sleep. Quote
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.