Ratings | | Unique User Downloads | | Download Rankings |
Not yet rated by the users | | Total: 55 | | All time: 10,609 This week: 673 |
|
Description | | Author |
This package can calculate the similarity level of two text strings.
It can take two text strings and apply algorithms to calculate a number that represents the similarity between those strings.
The class that implements the Hamming distance algorithm returns the number of text characters that are different in each string.
The class that implements the Levenshtein algorithm returns a number that represents the number of steps that are necessary to change the first string into the second strings. | |
 |
|
Innovation award
 Nominee: 2x |
|
Example
<?php
require_once 'vendor/autoload.php';
$action = new \Anzawi\App\Action();
if ($_GET && isset($_GET['first_string']) && isset($_GET['second_string'])) {
$data = $_GET;
$action->set($_GET['first_string'], $_GET['second_string']);
if ($action->validate()) {
$action->run();
}
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<?php if ($action->errors()): ?>
<p style="background-color: #ffcccc; color: red">
all fields are required!
</p>
<?php endif; ?>
<form action="/" method="get">
<label>
First string
<input type="text" maxlength="255" name="first_string" value="<?php echo $action->getFirstString() ?>">
</label>
<label>
Second string
<input type="text" maxlength="255" name="second_string" value="<?php echo $action->getSecondString()?>">
</label>
<button type="submit">Calculate</button>
</form>
<?php if($action->isSubmitted() === true): ?>
<div style="padding: 10px">
<div>
<table style="border: 2px solid;">
<tr>
<?php foreach ($action->getDiff() as $item): ?>
<td><?php echo $item; ?></td>
<?php endforeach; ?>
</tr>
</table>
</div>
<span>Levenshtein Distance: <?php echo $action->getLevenshtein() ?></span>
<br>
<span>Hamming Distance: <?php echo $action->getHamming() ?></span>
</div>
<?php endif; ?>
</body>
</html>
|
Details
find-diff
calculate levenshtein distances & hamming distances between 2 strings using PHP
please note : PHP provided build-in functions to do what this library do
it's just for fun !
levenshtein function
gmp_hamdist function
main Classes located in (/libs/
) directory
installation
-
open your `terminal`/`cmd`/`powershell`
-
navigate to your projects directory
-
run `git clone https://github.com/anzawi/find-diff.git`
-
navigate to project `cd find-diff`
-
run `composer install`
this project require find-diff
as a library
check composer.json
file and take a look on repositories
section.
run test in command-line
-
open your `terminal`/`cmd`/`powershell`
-
navigate to project directory
-
run `php runTest --s1="Mohammad" --s2="Mohammed"`
run test project
-
run any preferred php server
-
navigate to project
-
you will see a simple form
-
start testing
don't forget to run test using phpunit
./vendor/bin/phpunit
|
Applications that use this package |
|
No pages of applications that use this class were specified.
If you know an application of this package, send a message to the author to add a link here.