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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:59:49+00:00 2026-06-07T08:59:49+00:00

im using the following code to search for similar text. But for some reason

  • 0

im using the following code to search for similar text. But for some reason it only returns the same value no matter what i search. can someone see what the issue might be?

    $result = mysql_query("SELECT keyword FROM search");
$storeArray = Array();
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$storeArray[] =  $row['keyword'];  
      }
foreach ($storeArray as $key){
    //echo "'".$key."'";
}  



$my_word = $_POST['value'];

$all_words = array(
"'".$key."'"
);

$bestMatch = array('word' => $my_word, 'match' => 2);

foreach($all_words as $word) {
similar_text($word, $my_word, $percent);
if($percent > $bestMatch['match']) $bestMatch = array('word' => $word, 'match' =>     $percent);
}

if($bestMatch['match'] < 100) echo 'Did you mean: <strong>' . $bestMatch['word'] .   '</strong>';
  • 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-07T08:59:50+00:00Added an answer on June 7, 2026 at 8:59 am

    I edited it a little, tell me if this is what you want.

    $my_word = $_POST['value'];
    $bestMatch = array('word' => $my_word, 'match' => 2);
    $result = mysql_query("SELECT keyword FROM search");
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                //run similar text on each row
            similar_text($row['keyword'], $my_word, $percent);
                //if row has a better score, overwrite $bestMatch
            if ($percent > $bestMatch['match'])
                $bestMatch = array('word' => $row['keyword'], 'match' => $percent);
    }
    if ($bestMatch['match'] < 100)
        echo 'Did you mean: <strong>' . $bestMatch['word'] .   '</strong>';
    

    EDIT: don’t forget that similar_text was shown to give good results only for words who already have a big similarity (in terms of length mainly), I think it’s an 80% resemblance (combining both character counts and lengths). Not 100% sure though…

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

Sidebar

Related Questions

I am using following code to read text from a .txt file. But I
I using following code: var search = 'test'; if ($('#sku').find(search) ){ //alert(search); $(document).find(search).css('color','red'); <TABLE>
I am attempting to use the following code to search a database using words
I'm using the following PHP code to return a json string: $itemURL = 'http://***.***.***/search?tag=Football&affiliate_id=&max_results=3';
Using following code I try to get updated list of checkbuttons' corresponding text values,
I'm using the following code to search for addresses and list them on the
I am trying to search places from the GraphAPI using following code without luck.
I am using following code to start activity when user pressing search button on
I using the following code to find people on twitter. but it gives me
I am comparing two strings using following code string1.Contains(string2) but i am not getting

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.