3v4l.org

run code in 300+ PHP versions simultaneously
<?php ########################################### # Paulo Collares Moreira Neto # 27 de dezembro de 2011 # www.paulocollares.com.br ########################################### //Esta Função transforma o texto em minúsculo respeitando a acentuação function str_minuscula($texto) { $texto = strtr(strtolower($texto),"ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÜÚÞßÇ","àáâãäåæçèéêëìíîïðñòóôõö÷øùüúþÿç"); return $texto; } //Esta Função transforma o texto em maiúsculo respeitando a acentuação function str_maiuscula($texto) { $texto = strtr(strtoupper($texto),"àáâãäåæçèéêëìíîïðñòóôõö÷øùüúþÿç","ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÜÚÞßÇ"); return $texto; } //Esta Função transforma a primeira letra do texto em maiúsculo respeitando a acentuação function primaira_maiuscula($texto) { $texto = strtr(ucfirst($texto),"ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÜÚÞßÇ","àáâãäåæçèéêëìíîïðñòóôõö÷øùüúþÿç"); return $texto; } //Verifica se a palavra está toda em maiúscula function comparaPalavraMaiuscula($palavra){ $palavra=str_replace(" ","",$palavra); if ($palavra=="") return false; if ($palavra=="[:p:]") return false; if (strlen($palavra)<=1) return false; $palavra=ereg_replace("[^a-zA-Z0-9]", "", strtr($palavra, "áàãâéêíóôõúüçÁÀÃÂÉÊÍÓÔÕÚÜÇ ", "aaaaeeiooouucAAAAEEIOOOUUC_")); if ($palavra == str_maiuscula($palavra)) return true; return false; } ///////////////////////////////// //Filtro ///////////////////////////////// function filtro($texto){ //Variáveis $pontuacoes=array(",",".","!","?",";"); $array_abreviado=array("vc","tb","jesus","naum","ñ","pq"); $array_abr_certo=array("você","também","Jesus","não","não","porque"); //Prepara paragrafo $texto=str_replace(" ","[:p:]",$texto); //acerta maiúscula e minúscula e inicia as sentenças com a primeira letra maiúscula $array=explode(" ",$texto); $novo_texto=""; $tam_array=count($array); for ($i=0;$i<$tam_array;$i++){ $palavra=$array[$i]; if(comparaPalavraMaiuscula($palavra)) $nova_palavra=str_minuscula($palavra); else $nova_palavra=$palavra; $caracter_anterior=substr($array[$i-1],-1); $caracter_anterior_paragrafo=substr($array[$i-1],-5); if ($caracter_anterior=="." || $caracter_anterior=="!" || $caracter_anterior=="?" || $caracter_anterior_paragrafo=="[:p:]" || $i==0) $nova_palavra=primaira_maiuscula($nova_palavra); $novo_texto.=$nova_palavra." "; } $texto=$novo_texto; //Adicionar espaçoes depois das pontuações e remover antes for ($i=0;$i<count($pontuacoes);$i++){ $ponto=$pontuacoes[$i]; $texto=str_replace(" ".$ponto." ",$ponto." ",$texto); $texto=str_replace(" ".$ponto,$ponto." ",$texto); $texto=str_replace($ponto,$ponto." ",$texto); } //acerta parênteses $texto=str_replace(" ( "," (",$texto); $texto=str_replace("( "," (",$texto); $texto=str_replace("("," (",$texto); $texto=str_replace(" ) ",") ",$texto); $texto=str_replace(" )",") ",$texto); $texto=str_replace(")",") ",$texto); //acerta redicencias $texto=str_replace(". . .","...",$texto); //remove mais de uma ! e ? $texto=str_replace("! ! ! ","!",$texto); $texto=str_replace("! ! ","!",$texto); $texto=str_replace("!!","!",$texto); $texto=str_replace("? ? ? ","?",$texto); $texto=str_replace("? ? ","?",$texto); $texto=str_replace("??","?",$texto); //remover espaçoes em branco extras $texto=str_replace(" "," ",$texto); $texto=str_replace(" "," ",$texto); $texto=str_replace(" "," ",$texto); //Adicionar paragrafo $texto=str_replace("\n","",$texto); $texto=str_replace("\r","",$texto); for ($i=0;$i<=10;$i++) $texto=str_replace("[:p:][:p:]","[:p:]",$texto); $array=explode("[:p:]",$texto); $novo_texto=""; $tam_array=count($array); for ($i=0;$i<$tam_array;$i++){ $paragrafo=$array[$i]; $paragrafo=trim($paragrafo); $paragrafo=trim($paragrafo,","); $paragrafo=primaira_maiuscula($paragrafo); if ($paragrafo=="") break; $ultimo_caracter=substr($paragrafo,-1); if ($ultimo_caracter!='.' && $ultimo_caracter!='!' && $ultimo_caracter!='?' && $ultimo_caracter!=':' && $ultimo_caracter!=';') $paragrafo.="."; if ($i!=$tam_array) $novo_texto.=$paragrafo." "; } $texto=$novo_texto; //Expandir palavras abreviadas $texto=str_replace($array_abreviado,$array_abr_certo,$texto); return $texto; } echo filtro($_POST['texto']); ?>
Output for 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Warning: Undefined array key "texto" in /in/RqeTY on line 157 Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /in/RqeTY on line 57 Warning: Undefined array key -1 in /in/RqeTY on line 73 Deprecated: substr(): Passing null to parameter #1 ($string) of type string is deprecated in /in/RqeTY on line 73 Warning: Undefined array key -1 in /in/RqeTY on line 74 Deprecated: substr(): Passing null to parameter #1 ($string) of type string is deprecated in /in/RqeTY on line 74
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Warning: Undefined array key "texto" in /in/RqeTY on line 157 Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /in/RqeTY on line 57 Warning: Undefined array key -1 in /in/RqeTY on line 73 Deprecated: substr(): Passing null to parameter #1 ($string) of type string is deprecated in /in/RqeTY on line 73 Warning: Undefined array key -1 in /in/RqeTY on line 74 Deprecated: substr(): Passing null to parameter #1 ($string) of type string is deprecated in /in/RqeTY on line 74
Output for 8.1.0 - 8.1.28
Warning: Undefined array key "texto" in /in/RqeTY on line 157 Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /in/RqeTY on line 58 Warning: Undefined array key -1 in /in/RqeTY on line 73 Deprecated: substr(): Passing null to parameter #1 ($string) of type string is deprecated in /in/RqeTY on line 73 Warning: Undefined array key -1 in /in/RqeTY on line 74 Deprecated: substr(): Passing null to parameter #1 ($string) of type string is deprecated in /in/RqeTY on line 74
Output for 8.0.0 - 8.0.30
Warning: Undefined array key "texto" in /in/RqeTY on line 157 Warning: Undefined array key -1 in /in/RqeTY on line 73 Warning: Undefined array key -1 in /in/RqeTY on line 74
Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.25, 7.4.27 - 7.4.33
Notice: Undefined index: texto in /in/RqeTY on line 157 Notice: Undefined offset: -1 in /in/RqeTY on line 73 Notice: Undefined offset: -1 in /in/RqeTY on line 74
Output for 7.3.32 - 7.3.33, 7.4.26

preferences:
248.89 ms | 401 KiB | 291 Q