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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:44:35+00:00 2026-06-09T04:44:35+00:00

I created an array to fetch a file and then parse the contents of

  • 0

I created an array to fetch a file and then parse the contents of that file. I already filtered out the words less than 4 characters with if(strlen($value) < 4): unset($content[$key]); endif;

My question is this – I want to remove common words from the array, but there is quite a few of them. Instead of doing these checks over and over and over on each array value, I was wondering if there was a more efficient way to do this?

Here’s a sample of the code I currently am using. This list could be huge and I am thinking that there has to be a better(more efficient) way?

foreach ($content as $key=>$value) {
    if(strlen($value) < 4): unset($content[$key]); endif; 
    if($value == 'that'): unset($content[$key]); endif;
    if($value == 'have'): unset($content[$key]); endif;
    if($value == 'with'): unset($content[$key]); endif;
    if($value == 'this'): unset($content[$key]); endif;
    if($value == 'your'): unset($content[$key]); endif;
    if($value == 'will'): unset($content[$key]); endif;
    if($value == 'they'): unset($content[$key]); endif;
    if($value == 'from'): unset($content[$key]); endif;
    if($value == 'when'): unset($content[$key]); endif;
    if($value == 'then'): unset($content[$key]); endif;
    if($value == 'than'): unset($content[$key]); endif;
    if($value == 'into'): unset($content[$key]); endif;
}
  • 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-09T04:44:37+00:00Added an answer on June 9, 2026 at 4:44 am

    Here’s how I’d do it:

    $exlcuded_words = array( 'that','have','with','this','your','will','they','from','when','then','than','into');
    $replace = array_fill_keys($exlcuded_words,'');
    echo str_replace(array_keys($replace),$replace,'some words that have to be with this your will they have from when then that into replaced');
    

    The way it works: make an array, full of empty strings, where the keys are the substrings you want to remove/replace. the just use str_replace, pass the keys as a first argument, the array itself as the second argument and, in the result in this case is: some words to be replaced. This code has been tested and works just fine.

    When dealing with an array, just implode it with some wacky delimiter (like %@%@% or something) and str_replace the lot, explode the lot again and Bob’s your uncle


    When it comes to replacing all words with less than 3 characters (which I forgot about in my original answer), that’s something a regex is good at… I’d say something like preg_replace('(\b|[^a-z])[a-z]{1,3}(\b|[^a-z])/i','$1$2',implode(',',$targetArray)); or someting like that.
    You might want to test this one out, because this is just off the top of my head, and untested. But this would seem to enough to get you started

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

Sidebar

Related Questions

I have created an array in php that prints this Array ( [mark] =>
Let's say you want to construct an Iterator that spits out File objects. What
i have created Array of Linkbutton and when user click on link button it
I have created an array square(40) as picturebox. I have to assign 40 picture
I have an array created with this code: var widthRange = new Array(); widthRange[46]
I have created an array Man: public main blah blah{ man = man[10]; }
I am trying to iterate a multidimension array created with the following line To
I created a multidimensional array called current_map . I am trying to access current_map
I have an array of strings. The array was created by parsing a long
I am new to Knockout.js, I have created an observable array and initialized with

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.