snipt

Ctrl+h for KB shortcuts

PHP

Converte acêntos em palavras para o código em HTML

<?php

function acento_para_html($umarray){
	$comacento = array('Á','á','Â','â','À','à','Ã','ã','É','é','Ê','ê','È','è','Ó','ó','Ô','ô','Ò','ò','Õ','õ','Í','í','Î','î','Ì','ì','Ú','ú','Û','û','Ù','ù','Ç','ç',);
	$acentohtml   = array('&Aacute;','&aacute;','&Acirc;','&acirc;','&Agrave;','&agrave;','&Atilde;','&atilde;','&Eacute;','&eacute;','&Ecirc;','&ecirc;','&Egrave;','&egrave;','&Oacute;','&oacute;','&Ocirc;','&ocirc;','&Ograve;','&ograve;','&Otilde;','&otilde;','&Iacute;','&iacute;','&Icirc;','&icirc;','&Igrave;','&igrave;','&Uacute;','&uacute;','&Ucirc;','&ucirc;','&Ugrave;','&ugrave;','&Ccedil;','&ccedil;');
	$umarray  = str_replace($comacento, $acentohtml, $umarray);
	return $umarray;
}

?>
https://snipt.net/embed/2cc1cd23a3058651081a51dfc5da8075/
/raw/2cc1cd23a3058651081a51dfc5da8075/
2cc1cd23a3058651081a51dfc5da8075
php
PHP
10
2019-07-17T00:23:09
True
False
False
/api/public/snipt/280/
converte-acentos-em-palavras-para-o-codigo-em-html
<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> <a href="#L-8"> 8</a> <a href="#L-9"> 9</a> <a href="#L-10">10</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><span id="L-3"><a name="L-3"></a><span class="k">function</span> <span class="nf">acento_para_html</span><span class="p">(</span><span class="nv">$umarray</span><span class="p">){</span> </span><span id="L-4"><a name="L-4"></a> <span class="nv">$comacento</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><span id="L-5"><a name="L-5"></a> <span class="nv">$acentohtml</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span><span class="s1">&#39;&amp;Aacute;&#39;</span><span class="p">,</span><span class="s1">&#39;&amp;aacute;&#39;</span><span class="p">,</span><span class="s1">&#39;&amp;Acirc;&#39;</span><span class="p">,</span><span class="s1">&#39;&amp;acirc;&#39;</span><span class="p">,</span><span class="s1">&#39;&amp;Agrave;&#39;</span><span class="p">,</span><span class="s1">&#39;&amp;agrave;&#39;</span><span class="p">,</span><span class="s1">&#39;&amp;Atilde;&#39;</span><span class="p">,</span><span class="s1">&#39;&amp;atilde;&#39;</span><span class="p">,</span><span class="s1">&#39;&amp;Eacute;&#39;</span><span class="p">,</span><span class="s1">&#39;&amp;eacute;&#39;</span><span class="p">,</span><span class="s1">&#39;&amp;Ecirc;&#39;</span><span class="p">,</span><span class="s1">&#39;&amp;ecirc;&#39;</span><span class="p">,</span><span class="s1">&#39;&amp;Egrave;&#39;</span><span class="p">,</span><span class="s1">&#39;&amp;egrave;&#39;</span><span class="p">,</span><span class="s1">&#39;&amp;Oacute;&#39;</span><span class="p">,</span><span class="s1">&#39;&amp;oacute;&#39;</span><span class="p">,</span><span class="s1">&#39;&amp;Ocirc;&#39;</span><span class="p">,</span><span class="s1">&#39;&amp;ocirc;&#39;</span><span class="p">,</span><span class="s1">&#39;&amp;Ograve;&#39;</span><span class="p">,</span><span class="s1">&#39;&amp;ograve;&#39;</span><span class="p">,</span><span class="s1">&#39;&amp;Otilde;&#39;</span><span class="p">,</span><span class="s1">&#39;&amp;otilde;&#39;</span><span class="p">,</span><span class="s1">&#39;&amp;Iacute;&#39;</span><span class="p">,</span><span class="s1">&#39;&amp;iacute;&#39;</span><span class="p">,</span><span class="s1">&#39;&amp;Icirc;&#39;</span><span class="p">,</span><span class="s1">&#39;&amp;icirc;&#39;</span><span class="p">,</span><span class="s1">&#39;&amp;Igrave;&#39;</span><span class="p">,</span><span class="s1">&#39;&amp;igrave;&#39;</span><span class="p">,</span><span class="s1">&#39;&amp;Uacute;&#39;</span><span class="p">,</span><span class="s1">&#39;&amp;uacute;&#39;</span><span class="p">,</span><span class="s1">&#39;&amp;Ucirc;&#39;</span><span class="p">,</span><span class="s1">&#39;&amp;ucirc;&#39;</span><span class="p">,</span><span class="s1">&#39;&amp;Ugrave;&#39;</span><span class="p">,</span><span class="s1">&#39;&amp;ugrave;&#39;</span><span class="p">,</span><span class="s1">&#39;&amp;Ccedil;&#39;</span><span class="p">,</span><span class="s1">&#39;&amp;ccedil;&#39;</span><span class="p">);</span> </span><span id="L-6"><a name="L-6"></a> <span class="nv">$umarray</span> <span class="o">=</span> <span class="nb">str_replace</span><span class="p">(</span><span class="nv">$comacento</span><span class="p">,</span> <span class="nv">$acentohtml</span><span class="p">,</span> <span class="nv">$umarray</span><span class="p">);</span> </span><span id="L-7"><a name="L-7"></a> <span class="k">return</span> <span class="nv">$umarray</span><span class="p">;</span> </span><span id="L-8"><a name="L-8"></a><span class="p">}</span> </span><span id="L-9"><a name="L-9"></a> </span><span id="L-10"><a name="L-10"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
html, php, str_replace