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>
Output for 8.3.0 - 8.3.6
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html;" /> <title>Palindromes</title> </head> <body> Warning: fopen(): open_basedir restriction in effect. File(palindromes.txt) is not within the allowed path(s): (/tmp:/in:/etc) in /in/etKJQ on line 42 Warning: fopen(palindromes.txt): Failed to open stream: Operation not permitted in /in/etKJQ on line 42 Fatal error: Uncaught TypeError: fgets(): Argument #1 ($stream) must be of type resource, false given in /in/etKJQ:43 Stack trace: #0 /in/etKJQ(43): fgets(false) #1 {main} thrown in /in/etKJQ on line 43
Process exited with code 255.
Output for 8.0.0 - 8.0.12, 8.0.14 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html;" /> <title>Palindromes</title> </head> <body> Warning: fopen(): open_basedir restriction in effect. File(palindromes.txt) is not within the allowed path(s): (/tmp:/in:/etc) in /in/etKJQ on line 42 Warning: fopen(palindromes.txt): Failed to open stream: Operation not permitted in /in/etKJQ on line 42 Fatal error: Uncaught TypeError: fgets(): Argument #1 ($stream) must be of type resource, bool given in /in/etKJQ:43 Stack trace: #0 /in/etKJQ(43): fgets(false) #1 {main} thrown in /in/etKJQ on line 43
Process exited with code 255.
Output for 8.0.13
<!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 Fatal error: Uncaught TypeError: fgets(): Argument #1 ($stream) must be of type resource, bool given in /in/etKJQ:43 Stack trace: #0 /in/etKJQ(43): fgets(false) #1 {main} thrown in /in/etKJQ on line 43
Process exited with code 255.
Output for 7.3.32 - 7.3.33, 7.4.33
<!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, bool given in /in/etKJQ on line 43 0 Palindromes trouv&eacute;s : <br/> </body> </html>
Output for 7.3.0 - 7.3.31, 7.4.0 - 7.4.32
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html;" /> <title>Palindromes</title> </head> <body> Warning: fopen(): open_basedir restriction in effect. File(palindromes.txt) is not within the allowed path(s): (/tmp:/in:/etc) in /in/etKJQ on line 42 Warning: fopen(palindromes.txt): failed to open stream: Operation not permitted in /in/etKJQ on line 42 Warning: fgets() expects parameter 1 to be resource, bool given in /in/etKJQ on line 43 0 Palindromes trouv&eacute;s : <br/> </body> </html>
Output for 7.1.25 - 7.1.33, 7.2.0 - 7.2.33
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html;" /> <title>Palindromes</title> </head> <body> Warning: fopen(): open_basedir restriction in effect. File(palindromes.txt) is not within the allowed path(s): (/tmp:/in:/etc) in /in/etKJQ on line 42 Warning: fopen(palindromes.txt): failed to open stream: Operation not permitted 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 7.1.20
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html;" /> <title>Palindromes</title> </head> <body> Warning: fopen(): open_basedir restriction in effect. File(palindromes.txt) is not within the allowed path(s): (/tmp:/in) in /in/etKJQ on line 42 Warning: fopen(palindromes.txt): failed to open stream: Operation not permitted 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 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.10
<!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 4.3.2 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 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>

preferences:
274.03 ms | 402 KiB | 357 Q