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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:20:19+00:00 2026-05-25T22:20:19+00:00

I have two strings I need to compare. Let’s say for example that the

  • 0

I have two strings I need to compare. Let’s say for example that the strings are as follows:

$A = "A fox jumped over the log";
$B = "A fox jumped";

Now how would I compare these two strings in PHP in order to return a percentage of character matching.

So I would like my algorithm to return (for the example above)

10/20 or .5 Since $B has exactly half of the matches of the length of $A.

I figured I could iterate through each character, but this seemed a bit tedious and my research indicated that preg_match wouldn’t help me much here. Thanks for the help!

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

    Try the levenshtein or similar_text functions.

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

Sidebar

Related Questions

Let's say I have two strings like this: XABY XBAY A simple regex that
I have two strings that i need to compare, but even if they have
Let's say I have two strings: one is XML data and the other is
I have two documents with a simple schema that I need to compare: current
If I have two strings, and I need to compare them in ASCII order
I have this two strings of equal length, which I need to compare. I
I need to compare two strings that are of varying length and as such
So I have a dilemma. I need to compare two C-style strings and I
Say I have two strings, String s1 = AbBaCca; String s2 = bac; I
I have two arrays (or arraylists if it is easier) of strings. I need

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.