PHP code explanation question.
<p>I don't know if this id the place to ask this question so be kind if I am wrong.</p>

<p>I was wondering if someone can explain to me in detail what the following 3 code snippets below do.</p>

<p>Snippet 1</p>

<pre><code>if($str !== mb_convert_encoding(mb_convert_encoding($str, 'UTF-32', 'UTF-8'), 'UTF-8', 'UTF-32')){
    $str = mb_convert_encoding($str, 'UTF-8');
}
</code></pre>

<p>Snippet 2</p>

<pre><code>$str = preg_replace('`&amp;([a-z]{1,2})(acute|uml|circ|grave|ring|cedil|slash|tilde|caron|lig);`i', '\\1', $str);
</code></pre>

<p>Snippet 3</p>

<pre><code>$str = preg_replace(array('`[^a-z0-9]`i','`[-]+`'), '-', $str); 
</code></pre>

<p>Here is the full code below for reference.</p>

<pre><code>function to_permalink($str){
    if($str !== mb_convert_encoding(mb_convert_encoding($str, 'UTF-32', 'UTF-8'), 'UTF-8', 'UTF-32')){
        $str = mb_convert_encoding($str, 'UTF-8');
    }
        $str = htmlentities($str, ENT_NOQUOTES, 'UTF-8');
        $str = preg_replace('`&amp;([a-z]{1,2})(acute|uml|circ|grave|ring|cedil|slash|tilde|caron|lig);`i', '\\1', $str);
        $str = html_entity_decode($str, ENT_NOQUOTES, 'UTF-8');
        $str = preg_replace(array('`[^a-z0-9]`i','`[-]+`'), '-', $str);
        $str = strtolower(trim($str, '-'));
        return $str;
}
</code></pre>
