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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:23:18+00:00 2026-05-28T00:23:18+00:00

I have a sizeable txt file (3.5 MB) structured like so: sweep#1 expanse#1 0.375

  • 0

I have a sizeable txt file (3.5 MB) structured like so:

sweep#1 expanse#1   0.375
loftiness#1 highness#2  0.375
lockstep#1  0.25
laziness#2  0.25
treponema#1 0.25
rhizopodan#1 rhizopod#1 0.25
plumy#3 feathery#3 feathered#1  -0.125
ruffled#2 frilly#1 frilled#1    -0.125
fringed#2   -0.125
inflamed#3  -0.125
inlaid#1    -0.125

Each word is followed by a #, an integer and then its “score.” There are tab breaks in between the word and score. As of right now, the textfile is loaded as a string using file_get_contents().

From an array of strings made up of individual, lower-case, character-stripped words, I need to look up each value, find its corresponding score and add it to a running total.

I imagine I would need some form of regex to first find the word, continue to the next \t and then add the integer to a running total. What’s the best way of going about this?

  • 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-28T00:23:19+00:00Added an answer on May 28, 2026 at 12:23 am

    Yes, there are probably better ways of doing this. But this is so oh-so-simple:

    <?php
    
    $wordlist = file_get_contents("wordlist.txt");
    
    //string string of invalid chars and make it lowercase
    $string = "This is the best sentence ever! Winning!";
    $string = strtolower($string);
    $string = preg_replace('/[^\w\d_ -]/si', '', $string);
    $words = explode(" ", $string);
    
    $lines = explode("\n", $wordlist);
    $scores = array();
    foreach ($lines as $line) {
        $split = preg_split("/(\#|\t)/", $line); //split on # or tab
        $scores[$split[0]] = doubleval(array_pop($split));
        //split[0] (first element) contains the word
        //array_pop (last element) contains score
    }
    
    $total = 0;
    foreach($words as $word) {
        if (isset($scores[$word])) $total += $scores[$word];
    }
    
    echo $total;
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a sizeable interactive swf file and the file is embedded to my
I have a pretty sizeable object graph that I have serialized to a file
Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=
I have a number of records (=< 100) that contain sizeable chunks of text
I have run into this issue several times in the past and would like
I have a client with a database that has several sizeable and interrelational models.
I have a game that is fairly sizeable, 30-40-50 people in at most points
I'm very new to web-development (I feel like all my posts lately have started
I have created a sizable application javascript and jQuery. However my file structure is
You know, like Battlestar paper! I have given this a few goes but now

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.