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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:34:30+00:00 2026-06-12T02:34:30+00:00

I wanna read some text files in a folder line by line. for example

  • 0

I wanna read some text files in a folder line by line. for example of 1 txt :

Fast and Effective Text Mining Using Linear-time Document Clustering
Bjornar Larsen WORD2 Chinatsu Aone
SRA International AK, Inc.
4300 Fair Lakes Cow-l Fairfax, VA 22033

{bjornar-larsen, WORD1

I wanna remove line that does not contain of words = word, word2, word3, and does not end with dot .

so. from the example, the result will be :

Bjornar Larsen WORD2 Chinatsu Aone
SRA International, Inc.
{bjornar-larsen, WORD1

I am confused, hw to remove the line? it that possible? or can we replace them with a space?

here’s the code :

$url = glob($savePath.'*.txt');
foreach ($url as $file => $files) {
    $handle = fopen($files, "r") or die ('can not open file');
    $ori_content= file_get_contents($files);
    foreach(preg_split("/((\r?\n)|(\r\n?))/", $ori_content) as $buffer){
        $pos1 = stripos($buffer, $word1);
        $pos2 = stripos($buffer, $word2);
        $pos3 = stripos($buffer, $word3);
        $last = $str[strlen($buffer)-1];//read the las character
        if (true !== $pos1 OR true !== $pos2 OR true !==$pos3 && $last != '.'){
        //how to remove
        }
    }
}

please help me, thank you so much 🙂

  • 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-06-12T02:34:31+00:00Added an answer on June 12, 2026 at 2:34 am

    You’re using a !== true comparison to test the return-value of the stripos. !== true means “is not absolutely equal-to the boolean value true”. The return-value of stripos is numeric, unless the word doesn’t exist, in which case it’s false. In other words, your condition is always false.

    Try updating it to use === false instead. Also, you’re using OR in between each; Your example shows that it needs to only contain 1 of them – so if you’re checking that “none of them were found”, you’ll need to use && for everything:

    if (($pos1 === false) && ($pos2 === false) && ($pos3 === false) && ($last != '.'))
    

    Regarding “how to remove the line”, you’ll need to keep a list of all lines you want to keep. This means, we’ll actually want to flip the condition above to use !== false and an || between everything (because we want to keep all lines that match any rule).

    Try something like this:

    $url = glob($savePath.'*.txt');
    foreach ($url as $file => $files) {
        $handle = fopen($files, "r") or die ('can not open file');
        $ori_content= file_get_contents($files);
        $linesToKeep = array(); // list of all lines that match our rules
        foreach(preg_split("/((\r?\n)|(\r\n?))/", $ori_content) as $buffer){
            $pos1 = stripos($buffer, $word1);
            $pos2 = stripos($buffer, $word2);
            $pos3 = stripos($buffer, $word3);
            $last = $str[strlen($buffer)-1];
    
            if (($pos1 !== false) || ($pos2 !== false) || ($pos3 !== false) || ($last == '.')) {
                $linesToKeep[] = $buffer; // save this line
            }
        }
        // process list of lines for this file;
        // file_put_contents($files, join("\r\n", $linesToKeep)); // write back to file
        // $lines = join("\r\n", $linesToKeep); // convert to string to manipulate
    }
    

    Now, you’ll have every line that matches your ruleset in the $linesToKeep array. You can convert this back to a string with $lines = join("\r\n", $linesToKeep);, or iterate through it and process it however you’d like.

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

Sidebar

Related Questions

i wanna creat a website for downloading some files (pdf,word,xls, such as these files),
Okay, I am using (PHP) file_get_contents to read some websites, these sites have only
I wanna read text between <p></p> tags which comes from database field. I think
I'm using a background thread to read from a Sqlite database some GPS data...and
I wanna get all input from my pages timeline. so I read graph.facebook.com/pageid/feed with
I wanna get the string representation of a variable. For example, (def my-var {})
I wanna run selenium tests from TeamCity using Maven at Linux server without display.
I wanna to detect an input tag that its name is: some[en] in jquery.
i wanna read file in an other activity but i made it in another
I wanna ask guide about android application Compatibility,I am developing an application using Android

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.