<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.intl.grapheme.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'pt_BR',
  ),
  'this' => 
  array (
    0 => 'function.grapheme-levenshtein.php',
    1 => 'grapheme_levenshtein',
    2 => 'Calculate Levenshtein distance between two strings in grapheme units',
  ),
  'up' => 
  array (
    0 => 'ref.intl.grapheme.php',
    1 => 'Fun&ccedil;&otilde;es de Grapheme',
  ),
  'prev' => 
  array (
    0 => 'function.grapheme-extract.php',
    1 => 'grapheme_extract',
  ),
  'next' => 
  array (
    0 => 'function.grapheme-str-split.php',
    1 => 'grapheme_str_split',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/intl/grapheme/grapheme-levenshtein.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.grapheme-levenshtein" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">grapheme_levenshtein</h1>
  <p class="verinfo">(PHP 8 &gt;= 8.5.0)</p><p class="refpurpose"><span class="refname">grapheme_levenshtein</span> &mdash; <span class="dc-title">Calculate Levenshtein distance between two strings in grapheme units</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.grapheme-levenshtein-description">
  <h3 class="title">Descrição</h3>
  <p class="simpara">Estilo procedural</p>
  <div class="methodsynopsis dc-description">
   <span class="modifier">function</span> <span class="methodname"><strong>grapheme_levenshtein</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$string1</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$string2</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$insertion_cost</code><span class="initializer"> = 1</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$replacement_cost</code><span class="initializer"> = 1</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$deletion_cost</code><span class="initializer"> = 1</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$locale</code><span class="initializer"> = &quot;&quot;</span></span><br>): <span class="type"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="simpara">
   The Levenshtein distance is defined as the minimal number of
   grapheme clusters that have to be replaced, inserted, or deleted to transform
   <code class="parameter">string1</code> into <code class="parameter">string2</code>.
   The complexity of the algorithm is <code class="literal">O(m*n)</code>,
   where <code class="literal">n</code> and <code class="literal">m</code> are the
   length of <code class="parameter">string1</code> and
   <code class="parameter">string2</code> in grapheme units.
  </p>
  <p class="simpara">
   Unlike <span class="function"><a href="function.levenshtein.php" class="function">levenshtein()</a></span>, which operates on bytes, this
   function counts Unicode grapheme clusters, so composed and decomposed
   forms of the same character (e.g. <code class="literal">U+00E9</code> and
   <code class="literal">U+0065 U+0301</code>, both representing <code class="literal">é</code>)
   are treated as equivalent and have a distance of zero.
  </p>
  <p class="simpara">
   If <code class="parameter">insertion_cost</code>, <code class="parameter">replacement_cost</code>
   and/or <code class="parameter">deletion_cost</code> are unequal to <code class="literal">1</code>,
   the algorithm adapts to choose the cheapest transforms.
   For example, if <code class="literal">$insertion_cost + $deletion_cost &lt; $replacement_cost</code>,
   no replacements will be done, but rather inserts and deletions instead.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.grapheme-levenshtein-parameters">
  <h3 class="title">Parâmetros</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">string1</code></dt>
     <dd>
      <p class="simpara">
       One of the strings being evaluated for Levenshtein distance.
       Must be valid UTF-8.
      </p>
     </dd>
    
    
     <dt><code class="parameter">string2</code></dt>
     <dd>
      <p class="simpara">
       One of the strings being evaluated for Levenshtein distance.
       Must be valid UTF-8.
      </p>
     </dd>
    
    
     <dt><code class="parameter">insertion_cost</code></dt>
     <dd>
      <p class="simpara">
       Defines the cost of insertion. Must be greater than <code class="literal">0</code>.
      </p>
     </dd>
    
    
     <dt><code class="parameter">replacement_cost</code></dt>
     <dd>
      <p class="simpara">
       Defines the cost of replacement. Must be greater than <code class="literal">0</code>.
      </p>
     </dd>
    
    
     <dt><code class="parameter">deletion_cost</code></dt>
     <dd>
      <p class="simpara">
       Defines the cost of deletion. Must be greater than <code class="literal">0</code>.
      </p>
     </dd>
    
    
     <dt><code class="parameter">locale</code></dt>
     <dd>
      <p class="simpara">Localidade a ser usada.</p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.grapheme-levenshtein-returnvalues">
  <h3 class="title">Valor Retornado</h3>
  <p class="simpara">
   Returns the Levenshtein distance between the two strings, measured in
   grapheme units, or <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> on failure. Use
   <span class="function"><a href="function.intl-get-error-message.php" class="function">intl_get_error_message()</a></span> to retrieve details about
   the failure.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-function.grapheme-levenshtein-errors">
  <h3 class="title">Erros/Exceções</h3>
  <p class="simpara">
   Throws a <span class="exceptionname"><a href="class.valueerror.php" class="exceptionname">ValueError</a></span> if
   <code class="parameter">insertion_cost</code>, <code class="parameter">replacement_cost</code>,
   or <code class="parameter">deletion_cost</code> is less than or equal to
   <code class="literal">0</code>.
  </p>
  <p class="simpara">
   Returns <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> and sets an intl error if either input string is not
   valid UTF-8, if <code class="parameter">locale</code> is not a valid locale
   identifier, or if an internal ICU error occurs.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.grapheme-levenshtein-changelog">
  <h3 class="title">Registro de Alterações</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Versão</th>
      <th>Descrição</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.5.0</td>
      <td>
       This function has been added.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.grapheme-levenshtein-examples">
  <h3 class="title">Examples</h3>
  <div class="example" id="example-1">
   <p><strong>Exemplo #1 <span class="function"><strong>grapheme_levenshtein()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><pre><code style="color: #000000"><span style="color: #0000BB">&lt;?php

</span><span style="color: #FF8000">// Composed form (NFC): U+00E9 LATIN SMALL LETTER E WITH ACUTE
</span><span style="color: #0000BB">$e_composed </span><span style="color: #007700">= </span><span style="color: #DD0000">"\u{00E9}"</span><span style="color: #007700">;

</span><span style="color: #FF8000">// Decomposed form (NFD): U+0065 + U+0301 (e + combining acute accent)
</span><span style="color: #0000BB">$e_decomposed </span><span style="color: #007700">= </span><span style="color: #DD0000">"\u{0065}\u{0301}"</span><span style="color: #007700">;

</span><span style="color: #FF8000">// grapheme_levenshtein treats them as the same grapheme cluster
</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">grapheme_levenshtein</span><span style="color: #007700">(</span><span style="color: #0000BB">$e_composed</span><span style="color: #007700">, </span><span style="color: #0000BB">$e_decomposed</span><span style="color: #007700">));

</span><span style="color: #FF8000">// levenshtein() operates on bytes and sees them as different
</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">levenshtein</span><span style="color: #007700">(</span><span style="color: #0000BB">$e_composed</span><span style="color: #007700">, </span><span style="color: #0000BB">$e_decomposed</span><span style="color: #007700">));

</span><span style="color: #0000BB">?&gt;</span></code></pre></div>
   </div>

   <div class="example-contents"><p>O exemplo acima produzirá:</p></div>
   <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">int(0)
int(3)</pre>
</div>
   </div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.grapheme-levenshtein-seealso">
  <h3 class="title">Veja também</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.levenshtein.php" class="function" rel="rdfs-seeAlso">levenshtein()</a> - Calcula a dist&acirc;ncia Levenshtein entre duas strings</span></li>
    <li><span class="function"><a href="function.grapheme-strlen.php" class="function" rel="rdfs-seeAlso">grapheme_strlen()</a> - Obt&eacute;m o comprimento de uma string em unidade de grafema</span></li>
    <li><span class="function"><a href="function.grapheme-substr.php" class="function" rel="rdfs-seeAlso">grapheme_substr()</a> - Retorna parte de uma string</span></li>
    <li><span class="function"><a href="function.similar-text.php" class="function" rel="rdfs-seeAlso">similar_text()</a> - Calcula a similaridade entre duas strings</span></li>
    <li>
     <a href="http://unicode.org/reports/tr29/#Grapheme_Cluster_Boundaries" class="link external">&raquo;&nbsp;
      Unicode Text Segmentation: Grapheme Cluster Boundaries
     </a>
    </li>
   </ul>
  </p>
 </div>

</div><?php manual_footer($setup); ?>