SitePoint Sponsor

User Tag List

Page 2 of 3 FirstFirst 123 LastLast
Results 26 to 50 of 52

Thread: Open textfile

  1. #26
    SitePoint Guru
    Join Date
    Sep 2007
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sik that works good, but is there also a way to make it only open a .ini file if it was the test [Registered] on line 11 of the file?
    Animated Chatrooms - www.121chatrooms.net

  2. #27
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I'm not quite sure what you mean - do you mean if a certain string is on line 11?
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  3. #28
    SitePoint Guru
    Join Date
    Sep 2007
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok code is modified just trying to make it so it only outputs the file if on line 10 it says [Registered]
    Animated Chatrooms - www.121chatrooms.net

  4. #29
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    In which case, just check it:
    PHP Code:
    <?php 
    function filter_ini($file){ 
        return (!
    is_dir($file) && preg_match('/(.*)\.ini/'$file)); 

    $dir 'c:\\'
    if(!
    file_exists($dir) || !is_dir($dir)){ 
        die(
    'Folder "'.$dir.'" does not exist'); 

    if(
    substr($dir, -1) != '/'){ 
        
    $dir .= '/'

    $files scandir($dir1); 
    if(
    $files === false){ 
        die(
    'Folder "'.$dir.'" cannot be opened'); 

    $files array_filter($files'filter_ini'); 
    echo 
    'Files found in folder "' $dir '": '.count($files).'<ul>'
    foreach(
    $files as $file){ 
    $lines file($dir $file); 
        if(
    $lines !== false && strtolower(trim($lines[9])) == '[registered]'){
            echo 
    '<li>' htmlentities($lines[0]);
        }

    ?>
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  5. #30
    SitePoint Guru
    Join Date
    Sep 2007
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmm must be an error in that code all i get is Files found in folder "t:/rooms/": 7

    and i added [registered] in only 1 file
    Animated Chatrooms - www.121chatrooms.net

  6. #31
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Are you sure it's on the tenth line?
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  7. #32
    SitePoint Guru
    Join Date
    Sep 2007
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ah found my mistake i started couting by 1 instead of the firstline 0
    Animated Chatrooms - www.121chatrooms.net

  8. #33
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    So does it work?
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  9. #34
    SitePoint Guru
    Join Date
    Sep 2007
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    all good thank you
    Animated Chatrooms - www.121chatrooms.net

  10. #35
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Glad to help.

    Any more questions related to this task please post on this thread. I seem to be owning this PHP forum at the moment anyway .
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  11. #36
    SitePoint Guru
    Join Date
    Sep 2007
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    haha thats true your great just 1 last final question.

    On line 7 i have the text room=blah blah can i just change the text room to mode but only on that line? echo htmlentities($lines[7]);
    Animated Chatrooms - www.121chatrooms.net

  12. #37
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Do you mean actually change the file or just the string?

    If the latter, this is the best way, to be safe (i.e. only replace the correct instance):
    PHP Code:
    <?php
    $lines
    [7] = preg_replace('/room=(.*?)/''mode=$1'$lines[7]);
    ?>
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  13. #38
    SitePoint Guru
    Join Date
    Sep 2007
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    once again this guy with a genius
    Animated Chatrooms - www.121chatrooms.net

  14. #39
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    All part of being in a community.

    That's the main difference between people who visit very regularly (multiple times per day) and people who come to ask.

    People who visit regularly pick up on tips given to others, learn from examples and are always advancing with their work.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  15. #40
    SitePoint Guru
    Join Date
    Sep 2007
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmmm i modified the code to write to a text file but i noticed the 1st and 2nd line are combined together i want to seperate it by having the them on a seperate line what is wrong with it the code looks normal:

    PHP Code:
    $myFile "t:/test.txt";
    $fh fopen($myFile'w') or die("can't open file");
    $stringData "[$filename]\n";
    fwrite($fh$stringData);
    $stringData "$lines[1]\n";
    fwrite($fh$stringData);
    $stringData "$lines[2]\n";
    fwrite($fh$stringData);
    $stringData "$lines[3]\n";
    fwrite($fh$stringData);
    $stringData "$lines[4]\n";
    fwrite($fh$stringData);
    $stringData "$lines[6]\n";
    fwrite($fh$stringData);
    $stringData "$lines[7]\n";
    fwrite($fh$stringData);
    $lines[9] = preg_replace('/room=(.*?)/''modes=$1'$lines[9]);
    $stringData "$lines[9]\n";
    fwrite($fh$stringData);
    $stringData "Service_Idle";
    fwrite($fh$stringData);
    fclose($fh);
    }
    }
    }
    ?> 
    Animated Chatrooms - www.121chatrooms.net

  16. #41
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Can I see an example of test.txt?

    BTW, it's much easier to use this to write to the file:
    PHP Code:
    $myFile "t:/test.txt";
    $lines[9] = preg_replace('/room=(.*?)/''modes=$1'$lines[9]); 
    $stringData = <<<FILE
    [{$filename}]
    {$lines[1]}
    {$lines[2]}
    {$lines[3]} 
    {$lines[4]} 
    {$lines[6]} 
    {$lines[7]} 
    {$lines[9]}
    {Service_Idle}
    FILE;
    file_put_contents($myFile$stringData
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  17. #42
    SitePoint Guru
    Join Date
    Sep 2007
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    [&#37;#Music-Chat]topic=Music chat is here
    category=GN
    language=EN-US
    welcome=Welcome to the music chatroom, enjoy your stay
    owner=ada0d65aw1d8a4w/*-
    host=ad0ad+502a+95wd2a-*8
    modes=ntr
    Service_Idle[%#HelpDesk]topic=Live website/chat support Helpdesk
    category=GN
    language=EN-US
    welcome=Please wait for an staff member to assist you
    owner=0d0a5wd40aw4daw/d78a/
    host=ad0a6d0a984aw89
    modes=ntrm
    Service_Idle
    Animated Chatrooms - www.121chatrooms.net

  18. #43
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Does the code I posted above fix your problem?
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  19. #44
    SitePoint Guru
    Join Date
    Sep 2007
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nope didnt do anything at all
    Animated Chatrooms - www.121chatrooms.net

  20. #45
    SitePoint Member
    Join Date
    Aug 2008
    Location
    UK
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    why do you need to do this

  21. #46
    SitePoint Guru
    Join Date
    Sep 2007
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    its a web intergration script with an irc chat server
    Animated Chatrooms - www.121chatrooms.net

  22. #47
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I suspect that the original file has the issue, not the code.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  23. #48
    SitePoint Guru
    Join Date
    Sep 2007
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmm and there is no way to bypass it using my code so it drops to another line?
    Animated Chatrooms - www.121chatrooms.net

  24. #49
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    What do you get if you echo $lines[1]?
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  25. #50
    SitePoint Guru
    Join Date
    Sep 2007
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    topic=Music chat is here
    Animated Chatrooms - www.121chatrooms.net


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
  •