<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Calculate the similarity between two strings</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.sha1.html">sha1</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.soundex.html">soundex</a></div> <div class="up"><a href="ref.strings.html">String Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.similar-text" class="refentry"> <div class="refnamediv"> <h1 class="refname">similar_text</h1> <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">similar_text</span> — <span class="dc-title">Calculate the similarity between two strings</span></p> </div> <div class="refsect1 description" id="refsect1-function.similar-text-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">int</span> <span class="methodname"><strong>similar_text</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$first</code></span> , <span class="methodparam"><span class="type">string</span> <code class="parameter">$second</code></span> [, <span class="methodparam"><span class="type">float</span> <code class="parameter reference">&$percent</code></span> ] )</div> <p class="para rdfs-comment"> This calculates the similarity between two strings as described in Programming Classics: Implementing the World's Best Algorithms by Oliver (ISBN 0-131-00413-1). Note that this implementation does not use a stack as in Oliver's pseudo code, but recursive calls which may or may not speed up the whole process. Note also that the complexity of this algorithm is O(N**3) where N is the length of the longest string. </p> </div> <div class="refsect1 parameters" id="refsect1-function.similar-text-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">first</code></em></span> <dd> <p class="para"> The first string. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">second</code></em></span> <dd> <p class="para"> The second string. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">percent</code></em></span> <dd> <p class="para"> By passing a reference as third argument, <span class="function"><strong>similar_text()</strong></span> will calculate the similarity in percent for you. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.similar-text-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns the number of matching chars in both strings. </p> </div> <div class="refsect1 seealso" id="refsect1-function.similar-text-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="function.levenshtein.html" class="function" rel="rdfs-seeAlso">levenshtein()</a> - Calculate Levenshtein distance between two strings</span></li> <li class="member"> <span class="function"><a href="function.soundex.html" class="function" rel="rdfs-seeAlso">soundex()</a> - Calculate the soundex key of a string</span></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.sha1.html">sha1</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.soundex.html">soundex</a></div> <div class="up"><a href="ref.strings.html">String Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>