WP_Text_Diff_Renderer_Table::compute_string_distance( string $string1, string $string2 )

Computes a number that is intended to reflect the “distance” between two strings.


Parameters

$string1

(string) (Required)

$string2

(string) (Required)


Return

(int)


Source

File: wp-includes/class-wp-text-diff-renderer-table.php

	public function compute_string_distance( $string1, $string2 ) {
		// Vectors containing character frequency for all chars in each string
		$chars1 = count_chars($string1);
		$chars2 = count_chars($string2);

		// L1-norm of difference vector.
		$difference = array_sum( array_map( array($this, 'difference'), $chars1, $chars2 ) );

		// $string1 has zero length? Odd. Give huge penalty by not dividing.
		if ( !$string1 )
			return $difference;

		// Return distance per character (of string1).
		return $difference / strlen($string1);
	}


Changelog

Changelog
Version Description
WP-2.6.0 Introduced.