Buddi07 Posted December 19, 2007 Share Posted December 19, 2007 Hello I'm new one in forum so I want to say hi for everyone but I have big problem in php. I have a file which contain context. This file contain about 4-6 lines, it doesn't matter but anyway, I have been trying to write a script which open the file from specific path, then it should put everyline after linebreak in file (by clicking ENTER) into array value. I did this with file() function. Now the big problem is when I have done this then I want to make a function that read the file and check if there's two empty lines one after another and if it finds it then some function will be run. How I can do the whole mess? Please help Quote Link to comment Share on other sites More sharing options...
Buddi07 Posted December 19, 2007 Author Share Posted December 19, 2007 no one? Quote Link to comment Share on other sites More sharing options...
tromton Posted December 19, 2007 Share Posted December 19, 2007 i dont understand yur question. please try to formulate you question more clearly. also post you r code so someone can actually see what you are talking about. Quote Link to comment Share on other sites More sharing options...
Buddi07 Posted December 19, 2007 Author Share Posted December 19, 2007 Thank you for your reply. I will explain my situation more clearly. I'm now developing an announcement board. In this board I want that user can add, edit or delete all announcements that user write in file and in php script the date and horizontal line will added automaticly after each announcement that user writes in file. So I try to make an interface which is as easy to use as it can be. So I have following solution for that interface. This interface is working via file and this file must be a text file. The interface start first to read all lines in that specific file and if it notice when reading all lines in file two empty lines which order is one by another. Let's take an example. The following context is text from file called textfile.txt. 1. Hello, this is text 2. more text 3. another text? 4. 5. Lines 4. and 5. are empty. So when this interface will detect two lines one after another it will echo all the lines that will come after two empty lines. Let's take an example. The following context is text from file called textfile.txt. 1. Hello, this is text 2. more text 3. another text? 4. 5. 6. Hello again 7. more text 8. and again Now the interface that I wanted to develope will give following output: Hello, this is text more text another text (Date here) (Horizontal line here) Hello again more text and again (Date here) (Horizontal line here) and so on. The script is following that I have developed at moment: $file = file('textfile.txt'); $lines = count($file); foreach ($file as $val) { echo ("$val" . " here come br tag"); } $time = time(); $date = date("d/m/Y", $time); echo "<b><font size = 2>" . "Added on " . $date . "</font></b><br> <hr align=left width=150>"; } Okay I go through my problem again. My problems are: 1. How I can add each line to each array value and how I can use it? 2. How I can make a function that will detect two empty lines (same as two empty array values one after another) one after another? 3. What kind of script would be easy to use that will add every text lines after every two empty lines detection? Please tell me if you still don't understand my problem. Quote Link to comment Share on other sites More sharing options...
Buddi07 Posted December 19, 2007 Author Share Posted December 19, 2007 up. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 19, 2007 Share Posted December 19, 2007 Just do txt file TITLE:hello:USER:sensei:COMMENT:skjdaskjdaskdasjkdjaskdjaskjdskajdkasjkdjaskjdaskjdaskjkdasjdjaskjdaskjdkasjkdasjkjdaskjdaskdjaskjdaskjdaskjdsjdkasjdkasjdkasjdkjaskdjaskdj<br><br><br><br><br> script <?php fp = fopen('file.txt','r'); if (!$fp) {echo 'ERROR: Unable to open file.</table></body></html>'; exit;} while (!feof($fp)) { $line = fgets($fp, 1024); //use 2048 if very long lines list ($f_title, $title, $f_user, $user, $f_comment, $comment) = split ('\:', $line); echo $f_title.': ' . $title . '<br>'; echo $f_user.': ' . $user . '<br>'; echo $f_comment.': ' . $comment . '<br>'; } fclose($fp); ?> Quote Link to comment Share on other sites More sharing options...
Buddi07 Posted December 19, 2007 Author Share Posted December 19, 2007 Thank you very much for help I also found right now another solution Quote Link to comment Share on other sites More sharing options...
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.