SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    if ($zee == "Guru") { $zee--;}
    Join Date
    Nov 2005
    Location
    Karachi - Pakistan
    Posts
    1,134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Small Custom Blog Help

    Hello

    I am creating a mini Blog of mine WITHOUT ANY DATABASE. What I have setup is that people send their comment and that is stored in a text file on the server. and I am notified via email. Now When i click on the link on the email it opens a page that shows me the content of the text file,. if I approve that it has to be APPENDED to a blog page.

    on blog page I have some thing like this :
    <!-- Start of Comment -->

    <!-- End of Comment -->

    So I do not want this to be a PHP page, it is a HTML page. And every time I will approve a comment it will open a page like comments.html and append the new comment after the last <!-- End of Comment --> it will found.

    Please help me How to append ???

  2. #2
    SitePoint Addict
    Join Date
    Jul 2004
    Location
    Salem, OR
    Posts
    272
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not sure I understand the requirement. PHP is strictly a server side language and so it is not displayed from a client perspective i.e., if you looked at the source of a page generated entirely or partially via PHP you would generally only see HTML (or similar markup).

    Do you mean you don't want to use PHP as the underlying technology for this application, if so I am confused as to why you are posting the question on the PHP forum. Do you just want to use something like JavaScript instead?

    Assuming you are using PHP do you have any part of the application already written? Are you asking for someone to post up files of the application to your spec'?

    I am trying to figure out what question needs answering. So I suppose could you clarify a bit more?

  3. #3
    if ($zee == "Guru") { $zee--;}
    Join Date
    Nov 2005
    Location
    Karachi - Pakistan
    Posts
    1,134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am using PHP for all the tasks in this script. But the problem is that i do not want to use MySQL. I already have a page comment.html, and all i want to add the new Comment at the end of this page.

    some thing like I want to check the LAST OCCURRENCE of <! -- End of Comment --> and add my new comment there.

    Hummm, like this

    $mynewcomment = "<! -- End of Comment -->";
    $mynewcomment .= "<! -- Start of Comment -->";
    $mynewcomment .= $newly_approved_comment;
    $mynewcomment .= "<! -- End of Comment -->";

    and now what I want to do is that I want to Find the Last Occurrence of
    <! -- End of Comment --> in comments.html and will replace that $mynewcomment so it will put the End Comment tag for the previous comment back and add the new comment on it.

    Does it make sense ???

    Can u help me how to find the LAST OCCURRENCE of a String in a file ????

  4. #4
    SitePoint Addict
    Join Date
    Jul 2004
    Location
    Salem, OR
    Posts
    272
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, I'm sure this forum can help with that.

    In a nutshell you want to be able to open a flat file database e.g., database.txt, read out all the comments in it. Open comments.html and replace the last '<! -- End of Comment -->' w/ 'A_COMMENT+<! -- End of Comment -->'?

    This will be your source URL containing info., on every command you could think of in manipulating a filesystem:

    http://www.php.net/manual/en/ref.filesystem.php

    Specifically to open the database.txt or comments.html (to read or write) you will need to create a reference:

    http://www.php.net/manual/en/function.fopen.php

    Next you will need to read the information in to a variable to your script:

    http://www.php.net/manual/en/function.fread.php

    The manipulation you need to do on the contents depends on the format of your database.txt (could you post a sample). Once you have inserted your comment you need to write the file again:

    http://www.php.net/manual/en/function.fwrite.php

    And finally close the file handle.

  5. #5
    if ($zee == "Guru") { $zee--;}
    Join Date
    Nov 2005
    Location
    Karachi - Pakistan
    Posts
    1,134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks a lot for your support.

  6. #6
    SitePoint Member webxstudio's Avatar
    Join Date
    Feb 2007
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <?php 
    $myString = "Test string here."; 
    $fh=fopen('flat_file.txt',"a+"); 
    fwrite($fh,utf8_encode($myString)); 
    fclose($fh); 
    ?>
    No need to search for the 'ending comment' fwrite() will add your approved entry at the end of the text file due to the file pointer of the fopen() function.

    Search fopen() on php.net for more information.



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •