3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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>
Output for 5.3.0 - 5.6.28, 7.0.0 - 7.1.0
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html;" /> <title>Palindromes</title> </head> <body> Warning: fopen(palindromes.txt): failed to open stream: No such file or directory in /in/etKJQ on line 42 Warning: fgets() expects parameter 1 to be resource, boolean given in /in/etKJQ on line 43 0 Palindromes trouv&eacute;s : <br/> </body> </html>
Output for hhvm-3.10.0 - 3.12.0
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html;" /> <title>Palindromes</title> </head> <body> Warning: No such file or directory in /in/etKJQ on line 42 Warning: fgets() expects parameter 1 to be resource, boolean given in /in/etKJQ on line 43 0 Palindromes trouv&eacute;s : <br/> </body> </html>
Output for 4.3.2 - 5.2.17
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html;" /> <title>Palindromes</title> </head> <body> Warning: fopen(palindromes.txt): failed to open stream: No such file or directory in /in/etKJQ on line 42 Warning: fgets(): supplied argument is not a valid stream resource in /in/etKJQ on line 43 0 Palindromes trouv&eacute;s : <br/> </body> </html>
Output for 4.3.0 - 4.3.1
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html;" /> <title>Palindromes</title> </head> <body> Warning: fopen(palindromes.txt) [http://www.php.net/function.fopen]: failed to create stream: No such file or directory in /in/etKJQ on line 42 Warning: fgets(): supplied argument is not a valid stream resource in /in/etKJQ on line 43 0 Palindromes trouv&eacute;s : <br/> </body> </html>