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

  • Home
  • SEARCH
  • 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 8790017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:32:49+00:00 2026-06-13T22:32:49+00:00

Help please to compare two strings and take the difference between them in percent

  • 0

Help please to compare two strings and take the difference between them in percent

I had two strings like:

first string:
253.0.0.0,253.0.0.0,253.0.0.0,253.0.0.0,253.0.0.0,253.0.0.0,253.0.0.0,253.0.0.0,253.0.0.0,253.0.0.0,253.0.0.0,253.0.0.0,247.0.0.24,197.0.0.35,189.0.0.98....
second string:
255.255.255.127,255.255.255.127,255.255.255.127,255.255.255.127,255.255.255.127,255.255.255.127,255.255.255.127,255.255.255.127,255.255.255.127....

$first_array = explode(",", $out_string);
$second_array = explode(",", $out_string_1);
$result_array = array_merge(array_diff($first_array, $second_array), array_diff($second_array, $first_array));

$result = implode(",",$result_array);
echo $result;
  • 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-13T22:32:50+00:00Added an answer on June 13, 2026 at 10:32 pm

    There are two interesting native functions for this purpose, similar_text() and levenshtein()

    Example of similar_text():

    $string1 = 'AAAb';
    $string2 = 'aaab';
    
    similar_text ( $string1, $string2, $percentege );
    
    echo $percentege . '%'; // Output: 25%
    

    Example of levenshtein():

    levenshtein($string1, $string2, 1, 1000, 1000000);
    

    EDIT 1

    Considering that the first string always have the same quantity of entries that second string, you can try the below code. I’ve created two strings for test purpose, second string has two equal entries and 7 different entries in a total of 9.

    $first_string = '253.0.0.1,253.0.0.2,253.0.0.3,253.0.0.4,253.0.0.5,253.0.0.6,253.0.0.7,253.0.0.8,253.0.0.9';
    
    $second_string = '253.0.0.1,253.0.0.2,255.255.255.127,255.255.255.128,255.255.255.129,255.255.255.130,255.255.255.131,255.255.255.132,255.255.255.133';
    
    $first_array = explode(',', $first_string);
    
    $second_array = explode(',', $second_string);
    
    $total_entries = count($first_array);
    
    $array_differences = array_diff($first_array, $second_array);
    
    $different_entries = count($array_differences);
    
    $percentage = ( $different_entries / $total_entries ) * 100 ;
    
    echo 'Difference: ' . round($percentage, 2) . '%';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

please help me arrange these 3 buttons horizontally like this photoshopped image: Please take
Please, help me to compare complexity of two algorithms. O(N+1000) + O(M*log(M)) O(N*5) +
Could some one please help to compare two files, i have used the below
could soemone help me with the following condition, please? I'm trying to compare $price
Help please on how to extract data like 15,Teaching Periods 1 and 2.,Max 150.
Please help me somebody to convert unicodestring into string This is how i am
Please tell me how to compare 2 string variables I'm not talking about a
I want to compare two floats in PHP, like in this sample code: $a
I have two strings with me: s1=MICROSOFT s2=APPLESOFT I need to compare the strings
I need to compare and match the longest match of two strings in two

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.