Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1089961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:18:13+00:00 2026-05-16T23:18:13+00:00

i need to do a file search with php, and i have the filename

  • 0

i need to do a file search with php, and i have the filename search down, with glob, but i still need to search inside files.

i have a prototype, at tann98.vacau.com/file-search, but i need keywords, and suggestions. plus it needs to look inside files to find matches.

does anyone have ideas on how to do this kinda thing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T23:18:14+00:00Added an answer on May 16, 2026 at 11:18 pm

    A very basic method would be to read each file into PHP and search through them with one of the string searching functions.

    //loop through all filenames and for each one:
    $contents = file_get_contents($filename) ;
    if (strpos($contents, $keyword) !== false) {
        //found a match!
    }
    

    However this is very inefficient, since you will have to do that file reading and searching every single time you perform a search.

    That’s why search engines create indexes of the entire files they know about in advance, and then just look into those indexes for the search keyword. If you want to look into that, you would need a separate script (say indexer.php) that will do something like this:

    • loop through each file, getting its contents
    • break those into words
    • keep a record of unique words found in that file
    • store that record in a database or file on disk

    And have it run every now and then to update its index. Its index could for example look like this:

    $words = array(
        'mobile' => array('filename1.txt', 'filename2.txt'),
        'answer' => array('filename3.txt', 'filename5.txt', 'filename6.txt'),
        //...
    
    );
    

    Then, when you are searching for a certain keyword, you just need to load the index from your index file or database and see which filenames that word is found in.

    if (isset($words[$keyword])) {
        echo "Found in: " . join(', ', $words[$keyword]) ;
    }
    

    And there you have a very simplistic way of doing something like this. Further down the road you can store the index into a database, count how many times a word is found in each file to provide more relevant results, etc etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a php file that can read the contents of other files perfectly
I need some help. Right now i have done a file search that will
A lot of files will be stored in the DB and I need file
I have a fixed-length data file need to persistence into database. I use a
I have a pdf file.I need to find all the hyperlinks available in that
I have a crystal report file I need make a tiny edit in. It
I have a file I need to rename to that of an existing file.
I have a client who is in need of a file based encryption /
I have a ListView containing file names. These file names need to be draggable
I'm going through a lot of files and on each file I need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.