Read a line of last input to a text file

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Ghost
    replied
    Originally posted by arnage View Post
    I can't believe, i need the code to see it and by the posted content of the file i just assumed that.
    Thats why i insist on posting codes when asking for help about the same code.
    In the future i will delete any such thread as it is stupid, i doubt that here are some psychics...
    Anyway, even better if it does add new line already.
    yeah at first even i didnt think it was new lines. i also thought it was 1 full line being seperated by alot of | (pipelines)
    but once i copied and pasted the text to my computer i noticed it was all on seperate lines and it made my job of making a piece of code to read it alot more easier.

    Leave a comment:


  • arnage
    replied
    I can't believe, i need the code to see it and by the posted content of the file i just assumed that.
    Thats why i insist on posting codes when asking for help about the same code.
    In the future i will delete any such thread as it is stupid, i doubt that here are some psychics...
    Anyway, even better if it does add new line already.

    Leave a comment:


  • Ghost
    replied
    Originally posted by arnage View Post
    In the case of adding \n at writing...

    PHP Code:
    foreach (explode('|'end(file('file.txt'))) as $k => $v) echo $v.'<br/>'
    i believe his code for writting the data to text file already adds the \n for new lines.
    his text file he supplied for this was actually all on new lines which you wouldnt see as \n is invisible once added to txt file.. it just doesnt look like here on forum due to forum codebox wordwrapping the data when displayed. ;)

    Leave a comment:


  • arnage
    replied
    Yeah, sure. ;)

    Leave a comment:


  • mantraJAYBEE
    replied
    Originally posted by arnage View Post
    In the case of adding \n at writing...

    PHP Code:
    foreach (explode('|'end(file('file.txt'))) as $k => $v) echo $v.'<br/>'
    That's basic..
    I was just confused in the case of many symbols..
    Thanx anyway..!

    Leave a comment:


  • arnage
    replied
    In the case of adding \n at writing...

    PHP Code:
    foreach (explode('|'end(file('file.txt'))) as $k => $v) echo $v.'<br/>'

    Leave a comment:


  • Ghost
    replied
    nice work. happy to help. didnt take me long to make the piece of code as part of it was already in my flatfile forum project code ive been writing up.

    happy to help.

    Leave a comment:


  • mantraJAYBEE
    replied
    Originally posted by Ghost View Post
    your very welcome.
    the shoutbox ***** is as a result of ur code.. I later spiced it up with substr(); for emotions and wordwrap to manage page width..
    Wish I can find a good logo maker now
    Last edited by arnage; 16.01.13, 13:05.

    Leave a comment:


  • Ghost
    replied
    your very welcome.

    Leave a comment:


  • mantraJAYBEE
    replied
    Originally posted by Ghost View Post
    PHP Code:
    <?php
    $File 
    'test.txt';
    $End_File file($File);
    for(
    $k 0$k<count($End_File); $k++)
    {
    /** we do nothing here, we just wanted to get to end of file for info. */}
    preg_match('/(.*?)\|(.*?)\|(.*?)\|(.*?)\|(.*?)\|(.*?)/i'$End_File[$k-1], $matches);
    $Latest_Post $matches[1].': '.$matches[2];
    echo 
    $Latest_Post;
    ?>
    ///
    //
    and if you wanted to read the info backwards. you could use array reverse
    PHP Code:
    $End_File array_reverse(file($File));
    ///
    // 
    heres a temp link to it working.


    how it works.
    used count to get to end of file.
    used preg match to match the data input set with |
    then echo'd first 2 matches only. name/message.
    Thanks Ghost bro.. Thats the exact code I wanted!

    Leave a comment:


  • Ghost
    replied
    PHP Code:
    <?php
    $File 
    'test.txt';
    $End_File file($File);
    for(
    $k 0$k<count($End_File); $k++)
    {
    /** we do nothing here, we just wanted to get to end of file for info. */}
    preg_match('/(.*?)\|(.*?)\|(.*?)\|(.*?)\|(.*?)\|(.*?)/i'$End_File[$k-1], $matches);
    $Latest_Post $matches[1].': '.$matches[2];
    echo 
    $Latest_Post;
    ?>
    ///
    //
    and if you wanted to read the info backwards. you could use array reverse
    PHP Code:
    $End_File array_reverse(file($File));
    ///
    // 
    heres a temp link to it working.


    how it works.
    used count to get to end of file.
    used preg match to match the data input set with |
    then echo'd first 2 matches only. name/message.

    Leave a comment:


  • mantraJAYBEE
    replied
    But there's a way to read it as it is.. I've seen it somewhere

    Leave a comment:


  • arnage
    replied
    Consider that in part of writing into file add "\n" at the end, that way its gonna pack it line by line and would be much easier to read just one line.
    In that case you can count lines and take one from the beginning of the file or from its end, depending to where its writing into file.

    Leave a comment:


  • Read a line of last input to a text file

    I have a text file with the following:

    Code:
    JAR |Welcome post your comment/request what you want one .smile. |127.0.0.1|Aug 22nd, 2012 - 10:55pm|jarloft|blaaaaa
    Hackyboy|Hey,this is just wat I thot! .lol.|127.0.0.1|Aug 22nd, 2012 - 10:59pm|jarloft.tk|jaysean@gamil.com
    Hackyboy|Welcum to the home of mobile downloads .smiles. |82.145.208.33|Aug 23rd, 2012 - 9:38pm|jarloft.tk|Hackyboy@fine.tk
    Young|Plz .sad. I need 2go + Opera ScreenShort @HACKYBOY help me out|82.145.208.171|Aug 25th, 2012 - 3:42pm|jarloft.tk|Hacky@gmail.com
    JAR|Are here to put smile .smile. in your face by uploading all requested so dont be sad .sad. becouse we have been busy fixing some errors|65.255.37.191|Sep 3rd, 2012 - 8:38pm|mega.tk|go@u.co
    JARLOFT|We Are here to put smile .smile. in your face by uploading all requested so dont be sad .sad. becouse we have been busy fixing some errors|65.255.37.191|Sep 3rd, 2012 - 8:42pm|mega.tk|g@m.co
    Deva|Please give php script like yours|116.202.134.57|Sep 4th, 2012 - 8:01am||obe@gmail.com
    JAR|All ready uploaded|82.145.208.31|Sep 6th, 2012 - 2:08am|jar.tk|H@m.co
    H4hope|.lol. Pls i need d script 4 reg,profile,login and forum dat i can use in any site|82.145.217.49|Sep 10th, 2012 - 3:04am|naija.tk|Incredible@yahoo.com
    JAR|Ok, dats is html work with one trick i will upload it|82.145.209.178|Sep 11th, 2012 - 8:00am|jar.tk|H@c.me
    Ken|Pls naijahost.tk is my webhost site and i login to my control panel after register but cant find the FTP access and details|141.0.8.192|Sep 24th, 2012 - 7:35pm|ken.tk|Kenn@gmail.com
    Blog|Hai... Join me http://m.de|82.145.210.126|Sep 25th, 2012 - 3:29pm|m.de|Admin@blog.es
    Deva|Please upload any php website|65.255.37.187|Sep 26th, 2012 - 6:44am||obet@gmail.com
    JAR|KENNERYZ go to our forum http://9j.tk DAVE check the site|65.255.37.195|Sep 27th, 2012 - 1:14pm||Ha@co.com
    Cl***ic|.sad.|82.145.216.71|Sep 29th, 2012 - 6:36am|cod.tk|Ad@yahoo.com
    Cl***ic|Pls i nid waploaded script|82.145.216.71|Sep 29th, 2012 - 6:37am|cd.tk|Adenu@yahoo.com
    Admin|Welcome .smile.|217.212.230.214|Jan 3rd, 2013 - 9:25pm|grandwap.tk|mjb@gmail.com

    and using fopen I want to show ONLY the last input as:
    echo '<b>$lastu:</b> $lastmsg';
    excluding time and IP address..
    i.e Admin: Welcome
    Can anybody pls help me?
    Last edited by mantraJAYBEE; 04.01.13, 08:31.
Working...
X