Results 1 to 2 of 2

Thread: Search text file

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    259

    Search text file

    How can I search for word in text file (Text.txt) using php and give me true if this word is found else false

    Thanks

  2. #2
    Fanatic Member twanvl's Avatar
    Join Date
    Dec 2001
    Posts
    771
    First you open the file, and read it:
    PHP Code:
    $file=join('',file('text1.txt')); 
    (Of course you can also use fopen, but this is shorter)

    Then you look for the word:
    PHP Code:
    if (strpos($word,$file)!==false//I'm not sure on the order of the arguments, maybe it should be the other way around
       
    echo 'word found';
    else
       echo 
    'word not found'

Posting Permissions

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



Click Here to Expand Forum to Full Width