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 4594322
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:48:42+00:00 2026-05-21T22:48:42+00:00

I’m trying to parse a text file word by word and I need to

  • 0

I’m trying to parse a text file word by word and I need to be able to to store the offset of each word from the beginning of the file so that I can then find the exact instance of the word in the text file. Now I’m dealing with some very large text files so I was wondering what is the most efficient way of doing this?

EDIT: Some more details.

I will have two tables in a database. Lets call them WORDS which stores the words and REFERENCES which a reference for each word to a file.

The REFERENCES table will be something like this:

id INT PRIMARY
file_id INT /* ID of the text file */
offset INT /* Offset from the start of the file to get to the start of the word */

Then each record of WORDS has a referenced_id which related to a record in REFERENCES.

This is a simplified example. In reality I’ll have another table that relates each record from WORDS to one or more records in REFERENCES as there may be many instances of each word in many files.

The purpose of all this is to be able to show exactly where the instances of the word have been found when searching. So when I find the word I can get it’s reference and then take an excerpt from the text file.

  • 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-21T22:48:42+00:00Added an answer on May 21, 2026 at 10:48 pm

    most effective bu time or by memory used?

    1. By time – load all file in memory and parse it.
      And then popup each word, storing it (word) length

    $page = file_get_contents( $file );
    $arr_w = explode( ” “, $page );

    $arr_c = array(); count of words
    $arr_o = array(); offset of words 🙂

    $c = 0;
    foreach ($arr_w as $w)
    {
    $c++;
    str_replace( $page, $w, “”, 1);
    $arr_c[$w]++;
    $arr_o[$c] = strlen($w) + 1;
    }

    This is just idea …

    1. By memory usage, – your will need continuously read file and analise. It is much differs from this example …
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Basically, what I'm trying to create is a page of div tags, each has
Does anyone know how can I replace this 2 symbol below from the string
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,

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.