Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 472 Vote(s) - 3.56 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Compare two string and display number of mismatching words from string

#1
I know there are many techniques and methods to comparing two `Strings`, and find out if two `Strings` are equal or not.
I want to do something like this:

Var Str1 = "Hello How are you?";
var Str2 = "Hello I am ravi.";

To compare `str2` with `str1` and display the number count of mismatching words.
Both strings contain 4 words each. It should display you missed three words from `str1`.

I have one web page (web task) where a user needs to listen an audio and transcribe it. So I want to know how many words user misses from the transcribed original audio.
Reply

#2
This is as simple as converting both the strings to an array and then computing the difference of arrays.

$arr1 = explode(' ', strtolower($str1));
$arr2 = explode(' ', strtolower($str2));
echo 'You missed ' . count(array_diff($arr1, $arr2)) . ' words from str 1';
Reply

#3
Find and format difference between two strings in PHP

Try This :

[To see links please register here]

Reply

#4
You can trim the chars like ',', '?' in the string. Then trans it to words array, and remove the duplicate one. Last compare the difference between user input arrays and standard arrays.

// parse a string to array
function words($string)
{
return array_unique(explode(' ', str_replace(['?', '.', ','], '', $string)));
}

dd(array_diff(words($array2), words($array1))); //here user input array2 is the first parameter.
Reply

#5
Use explode to convert the `Strings` to `Arrays` and count the difference between the two `Arrays`:

$Str1 = "Hello How are you?";
$Str2 = "Hello I am ravi";

$st1 = (explode(" ", $Str1));
$st2 = (explode(" ", $Str2));


$result = array_diff($st1, $st2);

echo count($result);
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through