snipt

Ctrl+h for KB shortcuts

PHP

Eliminar acentos con PHP

1
2
3
4
5
6
7
<?php
    function elimina_acentos($cadena){
        $tofind = array('à','á','â','ã','ä', 'ç', 'è','é','ê','ë', 'ì','í','î','ï', 'ñ', 'ò','ó','ô','õ','ö', 'ù','ú','û','ü', 'ý','ÿ', 'À','Á','Â','Ã','Ä', 'Ç', 'È','É','Ê','Ë', 'Ì','Í','Î','Ï', 'Ñ', 'Ò','Ó','Ô','Õ','Ö', 'Ù','Ú','Û','Ü', 'Ý');
        $replac = array('a','a','a','a','a', 'c', 'e','e','e','e', 'i','i','i','i', 'n', 'o','o','o','o','o', 'u','u','u','u', 'y','y', 'A','A','A','A','A', 'C', 'E','E','E','E', 'I','I','I','I', 'N', 'O','O','O','O','O', 'U','U','U','U', 'Y');
        return(strtr($cadena,$tofind,$replac));
    }
?>
https://snipt.net/embed/c1a405eed6bfaeab50494fb7c8e2f2e3/
/raw/c1a405eed6bfaeab50494fb7c8e2f2e3/
c1a405eed6bfaeab50494fb7c8e2f2e3
php
PHP
7
2019-06-16T20:36:50
True
False
False
Nov 22, 2012 at 02:18 PM
/api/public/snipt/50641/
eliminar-acentos-con-php
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a> <span class="k">function</span> <span class="nf">elimina_acentos</span><span class="p">(</span><span class="nv">$cadena</span><span class="p">){</span> </span><span id="L-3"><a name="L-3"></a> <span class="nv">$tofind</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span><span class="s1">&#39;à&#39;</span><span class="p">,</span><span class="s1">&#39;á&#39;</span><span class="p">,</span><span class="s1">&#39;â&#39;</span><span class="p">,</span><span class="s1">&#39;ã&#39;</span><span class="p">,</span><span class="s1">&#39;ä&#39;</span><span class="p">,</span> <span class="s1">&#39;ç&#39;</span><span class="p">,</span> <span class="s1">&#39;è&#39;</span><span class="p">,</span><span class="s1">&#39;é&#39;</span><span class="p">,</span><span class="s1">&#39;ê&#39;</span><span class="p">,</span><span class="s1">&#39;ë&#39;</span><span class="p">,</span> <span class="s1">&#39;ì&#39;</span><span class="p">,</span><span class="s1">&#39;í&#39;</span><span class="p">,</span><span class="s1">&#39;î&#39;</span><span class="p">,</span><span class="s1">&#39;ï&#39;</span><span class="p">,</span> <span class="s1">&#39;ñ&#39;</span><span class="p">,</span> <span class="s1">&#39;ò&#39;</span><span class="p">,</span><span class="s1">&#39;ó&#39;</span><span class="p">,</span><span class="s1">&#39;ô&#39;</span><span class="p">,</span><span class="s1">&#39;õ&#39;</span><span class="p">,</span><span class="s1">&#39;ö&#39;</span><span class="p">,</span> <span class="s1">&#39;ù&#39;</span><span class="p">,</span><span class="s1">&#39;ú&#39;</span><span class="p">,</span><span class="s1">&#39;û&#39;</span><span class="p">,</span><span class="s1">&#39;ü&#39;</span><span class="p">,</span> <span class="s1">&#39;ý&#39;</span><span class="p">,</span><span class="s1">&#39;ÿ&#39;</span><span class="p">,</span> <span class="s1">&#39;À&#39;</span><span class="p">,</span><span class="s1">&#39;Á&#39;</span><span class="p">,</span><span class="s1">&#39;Â&#39;</span><span class="p">,</span><span class="s1">&#39;Ã&#39;</span><span class="p">,</span><span class="s1">&#39;Ä&#39;</span><span class="p">,</span> <span class="s1">&#39;Ç&#39;</span><span class="p">,</span> <span class="s1">&#39;È&#39;</span><span class="p">,</span><span class="s1">&#39;É&#39;</span><span class="p">,</span><span class="s1">&#39;Ê&#39;</span><span class="p">,</span><span class="s1">&#39;Ë&#39;</span><span class="p">,</span> <span class="s1">&#39;Ì&#39;</span><span class="p">,</span><span class="s1">&#39;Í&#39;</span><span class="p">,</span><span class="s1">&#39;Î&#39;</span><span class="p">,</span><span class="s1">&#39;Ï&#39;</span><span class="p">,</span> <span class="s1">&#39;Ñ&#39;</span><span class="p">,</span> <span class="s1">&#39;Ò&#39;</span><span class="p">,</span><span class="s1">&#39;Ó&#39;</span><span class="p">,</span><span class="s1">&#39;Ô&#39;</span><span class="p">,</span><span class="s1">&#39;Õ&#39;</span><span class="p">,</span><span class="s1">&#39;Ö&#39;</span><span class="p">,</span> <span class="s1">&#39;Ù&#39;</span><span class="p">,</span><span class="s1">&#39;Ú&#39;</span><span class="p">,</span><span class="s1">&#39;Û&#39;</span><span class="p">,</span><span class="s1">&#39;Ü&#39;</span><span class="p">,</span> <span class="s1">&#39;Ý&#39;</span><span class="p">);</span> </span><span id="L-4"><a name="L-4"></a> <span class="nv">$replac</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span><span class="s1">&#39;a&#39;</span><span class="p">,</span><span class="s1">&#39;a&#39;</span><span class="p">,</span><span class="s1">&#39;a&#39;</span><span class="p">,</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">,</span> <span class="s1">&#39;e&#39;</span><span class="p">,</span><span class="s1">&#39;e&#39;</span><span class="p">,</span><span class="s1">&#39;e&#39;</span><span class="p">,</span><span class="s1">&#39;e&#39;</span><span class="p">,</span> <span class="s1">&#39;i&#39;</span><span class="p">,</span><span class="s1">&#39;i&#39;</span><span class="p">,</span><span class="s1">&#39;i&#39;</span><span class="p">,</span><span class="s1">&#39;i&#39;</span><span class="p">,</span> <span class="s1">&#39;n&#39;</span><span class="p">,</span> <span class="s1">&#39;o&#39;</span><span class="p">,</span><span class="s1">&#39;o&#39;</span><span class="p">,</span><span class="s1">&#39;o&#39;</span><span class="p">,</span><span class="s1">&#39;o&#39;</span><span class="p">,</span><span class="s1">&#39;o&#39;</span><span class="p">,</span> <span class="s1">&#39;u&#39;</span><span class="p">,</span><span class="s1">&#39;u&#39;</span><span class="p">,</span><span class="s1">&#39;u&#39;</span><span class="p">,</span><span class="s1">&#39;u&#39;</span><span class="p">,</span> <span class="s1">&#39;y&#39;</span><span class="p">,</span><span class="s1">&#39;y&#39;</span><span class="p">,</span> <span class="s1">&#39;A&#39;</span><span class="p">,</span><span class="s1">&#39;A&#39;</span><span class="p">,</span><span class="s1">&#39;A&#39;</span><span class="p">,</span><span class="s1">&#39;A&#39;</span><span class="p">,</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="s1">&#39;E&#39;</span><span class="p">,</span><span class="s1">&#39;E&#39;</span><span class="p">,</span><span class="s1">&#39;E&#39;</span><span class="p">,</span><span class="s1">&#39;E&#39;</span><span class="p">,</span> <span class="s1">&#39;I&#39;</span><span class="p">,</span><span class="s1">&#39;I&#39;</span><span class="p">,</span><span class="s1">&#39;I&#39;</span><span class="p">,</span><span class="s1">&#39;I&#39;</span><span class="p">,</span> <span class="s1">&#39;N&#39;</span><span class="p">,</span> <span class="s1">&#39;O&#39;</span><span class="p">,</span><span class="s1">&#39;O&#39;</span><span class="p">,</span><span class="s1">&#39;O&#39;</span><span class="p">,</span><span class="s1">&#39;O&#39;</span><span class="p">,</span><span class="s1">&#39;O&#39;</span><span class="p">,</span> <span class="s1">&#39;U&#39;</span><span class="p">,</span><span class="s1">&#39;U&#39;</span><span class="p">,</span><span class="s1">&#39;U&#39;</span><span class="p">,</span><span class="s1">&#39;U&#39;</span><span class="p">,</span> <span class="s1">&#39;Y&#39;</span><span class="p">);</span> </span><span id="L-5"><a name="L-5"></a> <span class="k">return</span><span class="p">(</span><span class="nb">strtr</span><span class="p">(</span><span class="nv">$cadena</span><span class="p">,</span><span class="nv">$tofind</span><span class="p">,</span><span class="nv">$replac</span><span class="p">));</span> </span><span id="L-6"><a name="L-6"></a> <span class="p">}</span> </span><span id="L-7"><a name="L-7"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
acentos, eliminar, php