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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:07:28+00:00 2026-05-20T02:07:28+00:00

I just got help from some on this site and was able to let

  • 0

I just got help from some on this site and was able to let a user upload a text file, and have the in the upload process grab the file and programatically search for keywords I specify. The script then counts how many times the word is found and outputs the entire line that it was found in into an array.

So the example results returns this when using this code:

$sceneINT = $sf->countKeyWord('INT', $file);

with my class looking like so:

public static function countKeyWord($word, $file){
    if(!$word)
        return NULL;

    $contents = file_get_contents($file);

    #standardise those line endings
    $contents = str_replace(array("\r","\r\n","\n\r","\n"),"\n",$contents);
    $lines = explode("\n", $contents);

    #find your result
    $result = $line_num = array();
    foreach($lines as $line_num => $l)
        if(strpos($l, $word)) {
            $result[] = $l;
            $line_nums[] = $line_num;
        }

    echo "<pre>"; // I am echoing out the results for debugging purpuses
    print_r($result);
    echo "</pre>";
    return count($result); //final result shown to the user will only be the count
}

The results from this look like this:

Array
(
    [0] =>   3     INT. MARTEY'S OFFICE - DAY                                      3
    [1] =>   4     INT. RONNEY'S OFFICE - DAY                                      4
    [2] =>   6     INT. - BREEZE'S APARTMENT - DAY                                 6
    [3] =>   9     INT. - WAREHOUSE/SOUNDSTAGE - DAY                               9
    [4] =>  11     INT. EXAM ROOM - DAY                                           11
    [5] =>  12     INT. RAJA'S OFFICE - LATER                                     12
    [6] =>  14     INT. RAJA'S OFFICE - LATER                                     14
    [7] =>  15     INT. LARGE OPERATING ROOM - DAY                                15
    [8] =>  16     INT. RAJA'S OFFICE - LATER                                     16
    [9] =>  17     INT. OLIVER'S CAR - DAY                                        17
    [10] =>  20     INT. - ROY THUNDER'S OFFICE - NIGHT                            20
    [11] =>  22     A 2ND CLIP FROM "GOLDEN GATE GUNS"- INT. BASEMENT - DAY        22
    [12] =>  27     INT. HOUSE WIFE #3'S HOUSE - LATER                             27
    [13] =>  29     INT.  LIBRARY - DAY                                            29
    [14] =>  31     INT.  COFFEE SHOP - NIGHT                                      31
    [15] =>  32     INT. WAITING AREA - DAY                                        32
    [16] =>  33     INT. CASTING OFFICE - DAY                                      33
    [17] =>  34     INT. CASTING OFFICE - DAY                                      34
    [18] =>  35     INT. WAITING AREA - DAY                                        35
    [19] =>  36     INT. WAITING AREA - LATER                                      36
    [20] =>  37     INT. MOTEL ROOM - DAY                                          37
    [21] =>         INT. WAITING AREA - LATER
    [22] =>  39     INT. WAITING AREA - DAY                                        39
    [23] =>  42     INT. WAITING AREA - DAY                                        42
    [24] =>  43     INT. CASTING OFFICE - DAY                                      43
    [25] =>  44     INT. AUDITION ROOM - DAY                                       44
    [26] =>         INT. AUDITION ROOM - DAY
    [27] =>  45     INT. WAITING AREA - DAY                                        45
    [28] =>  46     INT. CASTING OFFICE - DAY                                      46
    [29] =>  47     INT. AUDITION ROOM - DAY                                       47
    [30] =>  48     INT. CASTING OFFICE - DAY                                      48
    [31] =>  49     INT. WAITING AREA - DAY                                        49
    [32] =>  50     INT. AUDITION ROOM - DAY                                       50
    [33] =>  51     INT. CASTING OFFICE - DAY                                      51
    [34] =>  52     INT. WAITING AREA - DAY                                        52
    [35] =>  53     INT. CASTING OFFICE - DAY                                      53
    [36] =>  54     INT. BURGER JOINT  - NIGHT                                     54
)

I need to upload the results into a database;

Taking Array[0] for example I would need to prepare that line for the database to look like this

scene: 3
int_ext: INT
scene_name:    MARTEY'S OFFICE
day_night:    DAY

All that will go into 1 row in the database, I don’t know how to approach this. How can I take the result and split into what I need and then send it to the database so that ALL items found are stored when the user presses the SAVE button.

  • 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-20T02:07:28+00:00Added an answer on May 20, 2026 at 2:07 am

    Your code has some errors.

    • You create array $line_num but use $line_nums to add entries
    • You don’t use $line_nums, why do you create it?

    I would use a regular expression to find all relevant information:

    $contents = file_get_contents($file);
    $pattern = "!INT\. (.*?) - (MORNING|NIGHT|DAY|LATER)!si";
    preg_match_all($pattern, $contents, $matches);
    echo '<pre>';
    print_r($matches);
    echo '</pre>';
    

    .

    If you really need the line number, you have to go another way:

    Use preg_replace to replace all line breaks:

    //OLD: $contents = str_replace(array("\r","\r\n","\n\r","\n"),"\n",$contents);
    //replaces even empty rows
    $contents = preg_replace("!(\r|\n|\r\n\r\n|\r\r|\n\n)!s", "\n", $contents);
    

    You can use the the regexp of m4rc to split your data 😉

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

Sidebar

Related Questions

I just got help in how to compile this script a few mintues ago
I just got Delphi 2009 and have previously read some articles about modifications that
I just got a dedicated server from a hosting company, and for some reason,
I just got this error message: ... from c:/ruby/lib/ruby/gems/1.8/gems/... ... 10 levels... from c:/ruby/lib/ruby/gems/1.8/gems/...
Just got a request from my boss for an application I'm working on. Basically
Just got a question about generics, why doesn't this compile when using a generic
I just got through manually removing the bin\ and obj\ folders from around 30
first i want to say that this site has been a really big help
I've got some weird images I'm getting from some hardware at work. They're from
Just looking for some pointer before I head down the wrong path. I have

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.