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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:42:04+00:00 2026-06-08T06:42:04+00:00

Ok, so as I’m getting my hands dirty with PHP I’ve started playing around

  • 0

Ok, so as I’m getting my hands dirty with PHP I’ve started playing around with arrays, strings and the like.

Now I know that arrays have a neat feature called “array_count_values” which can help to determine what the most repeated entry is. I wasn’t able to find a string equivalent for this- will I need to convert the string to an array?

Basically, I want my code to determine what the most common (repeated) word is over a certain length in a given string.

Sans the character length qualification, this code can find the answer to the question of what is the most repeated word in an array:

<?php


$param[0]="Ted";
$param[1]="Mark";
$param[2]="Mark";
$param[3]="Ross"; 
$param[3]="Clarence"; 

function array_most_common($arr) 
{ 
  $counted = array_count_values($arr); 
  arsort($counted); 
  return(key($counted));     
}

$mostCommon = array_most_common($param);
echo $mostCommon;
?>

So what would make this doable with a string? And a character amount filter?

  • 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-08T06:42:06+00:00Added an answer on June 8, 2026 at 6:42 am

    With a string, you can just explode() or preg_split() on space to form an array. Using preg_split() is favorable as it will eliminate duplicate and extraneous whitespace that explode() will not.

    $array = preg_split( '/\s+/', "This is a pretty long long long string", -1, PREG_SPLIT_NO_EMPTY);
    

    Then, once you have an array, use array_filter() to remove those that don’t meet the character requirements:

    $threshold = 3;
    $filtered = array_filter( $array, function( $el) use( $threshold) {
        return strlen( $el) > $threshold;
    });
    

    Once you have the $filtered array, just use that in array_count_values().

    $counts = array_count_values( $filtered);
    arsort( $counts); 
    echo key( $counts) . ' -> ' . current( $counts); 
    

    Here is a demo, which prints:

    long -> 3 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I would like to count the length of a string with PHP. The string
I have a jquery bug and I've been looking for hours now, I can't
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I have some data like this: 1 2 3 4 5 9 2 6

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.