PHP Classes

File: libs/src/Hamming.php

Recommend this page to a friend!
  Classes of mohammad anzawi   PHP Similarity Between Two Strings   libs/src/Hamming.php   Download  
File: libs/src/Hamming.php
Role: Class source
Content type: text/plain
Description: Class source
Class: PHP Similarity Between Two Strings
Calculate the similarity level of two text strings
Author: By
Last change:
Date: 2 years ago
Size: 911 bytes
 

Contents

Class file image Download
<?php

namespace Anzawi\FindDiff;

class
Hamming
{
   
/**
     * Calculate Hamming distance between two strings
     * Note: In its simplest form the function will take only the two strings
     * as parameter and will calculate just the number
     * @param string $firstString One of the strings being evaluated for Hamming distance.
     * @param string $secondString One of the strings being evaluated for Hamming distance.
     * @return int
     */
   
public static function calculate(string $firstString, string $secondString): int
   
{
       
$i = 0;
       
$count = 0;
        while (isset(
$firstString[$i]) != '') {
            if (isset(
$firstString[$i]) && isset($secondString[$i])) {
                if (
$firstString[$i] != $secondString[$i]) {
                   
$count++;
                }
            }
           
$i++;
        }
        return
$count;
    }
}