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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T19:20:00+00:00 2026-05-20T19:20:00+00:00

Where can I find algorithms that values the spelling of misplaced characters more accurately

  • 0

Where can I find algorithms that values the spelling of misplaced characters more accurately than levenshtein() and php similar_text() methods?

Example:

similar_text('jonas', 'xxjon', $similar); echo $similar; // returns 60
similar_text('jonas', 'asjon', $similar); echo $similar; // returns 60 <- although more similar!
echo levenshtein('jonas', 'xxjon'); // returns 4
echo levenshtein('jonas', 'asjon'); // returns 4  <- although more similar!

/ Jonas

  • 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-20T19:20:00+00:00Added an answer on May 20, 2026 at 7:20 pm

    Here’s a solution that I’ve come up to. It’s based on Tim’s suggestion of comparing the order of subsequent charachters. Some results:

    • jonas / jonax : 0.8
    • jonas / sjona : 0.68
    • jonas / sjonas : 0.66
    • jonas / asjon : 0.52
    • jonas / xxjon : 0.36

    I’m sure i isn’t perfect, and that it could be optimized, but nevertheless it seems to produce the results that I’m after…
    One weak spot is that when strings have different length, it produces different result when the values are swapped…

    static public function string_compare($str_a, $str_b) 
    {
        $length = strlen($str_a);
        $length_b = strlen($str_b);
    
        $i = 0;
        $segmentcount = 0;
        $segmentsinfo = array();
        $segment = '';
        while ($i < $length) 
        {
            $char = substr($str_a, $i, 1);
            if (strpos($str_b, $char) !== FALSE) 
            {               
                $segment = $segment.$char;
                if (strpos($str_b, $segment) !== FALSE) 
                {
                    $segmentpos_a = $i - strlen($segment) + 1;
                    $segmentpos_b = strpos($str_b, $segment);
                    $positiondiff = abs($segmentpos_a - $segmentpos_b);
                    $posfactor = ($length - $positiondiff) / $length_b; // <-- ?
                    $lengthfactor = strlen($segment)/$length;
                    $segmentsinfo[$segmentcount] = array( 'segment' => $segment, 'score' => ($posfactor * $lengthfactor));
                } 
                else 
                {
                    $segment = '';
                    $i--;
                    $segmentcount++;
                } 
            } 
            else 
            {
                $segment = '';
                $segmentcount++;
            }
            $i++;
        }   
    
        // PHP 5.3 lambda in array_map      
        $totalscore = array_sum(array_map(function($v) { return $v['score'];  }, $segmentsinfo));
        return $totalscore;     
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know where I can find that algorithm? It takes a double and
I have yet to find an algorithm/implementation that can convert rgb(0, 96, 255) to
Could someone please point out a site where I can find an algorithm to
If we have a source string and encrypted string, can we find out algorithm/forumla
Where can I find an efficient algorithm for breaking lines of text for formatted
I can't seem to find an algorithm to compute the number of arrays within
In python how can i develop this algorithm to find common patterns in a
What algorithm can be used to find the longest path in an unweighted directed
Which algorithm do you recommend to find out the nearest node which can be
I can find the JS and HTML code in response by alert() . But

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.