3v4l.org

run code in 300+ PHP versions simultaneously
<?php // déclaration de variables $MotsAccent = array(); $Tb = array(); // mes fonctions function accents($text) { $text = htmlentities($text); $text = htmlspecialchars_decode($text); return $text; } function rep_fr_htmlaccents($chaine) { $patterns = array('/&acirc;/','/&auml;/','/&aacute;/','/&agrave;/','/&ecirc;/','/&euml;/','/&eacute;/','/&egrave;/','/&ocirc;/','/&ouml;/','/&oacute;/','/&ograve;/','/&ucirc;/','/&uuml;/','/&uacute;/','/&ugrave;/','/&icirc;/','/&iuml;/','/&iacute;/','/&igrave;/','/&ccedil;/','/&aelig;/'); $rep = array('a','a','a','a','e','e','e','e','o','o','o','o','u','u','u','u','i','i','i','i','c','o'); return preg_replace($patterns, $rep, $chaine); } function IsPalindrome($MotTeste) { $MotOrigine = rep_fr_htmlaccents($MotTeste); $MotInverse = strrev($MotOrigine); If ($MotInverse === $MotOrigine) { return $MotTeste; } return ""; } // fin de mes fonctions ?> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html;" /> <title>Palindromes</title> </head> <body> <?php //Début du programme $txt = fopen('palindromes.txt','r'); while ($line = fgets($txt)) { $mots=preg_split("/\W+/", $line); for ($i = 0; $i < count($mots); $i++) { if (strlen($mots[$i])>1) { $tef = accents($mots[$i]); array_push($MotsAccent, strtolower($tef)); } } } $MotsDedoubles = array_unique($MotsAccent); foreach($MotsDedoubles as $MotsDedouble) { if ($MotsDedouble!="") { $res = IsPalindrome($MotsDedouble); if ($res!="" && strlen($res)>1) { $Tb[] = $res; } } } echo count($Tb)." Palindromes trouv&eacute;s : <br/>"; for ($i = 0; $i < count($Tb); $i++) { echo $Tb[$i]."<br/>"; } ?> </body> </html>

preferences:
36.59 ms | 402 KiB | 5 Q