function main($argv) { if (count($argv) != 2) { echo "Invalid arguments. Usage :: php palindrome_check.php <your-word-be-asked-palindrome>\n"; exit(1); } $argv[1] .= is_palindrome(str_split($argv[1])) ? " is palindrome.\n" : " is NOT palindrome.\n"; echo $argv[1]; }
function reverse_and_add($num) { $i = 0; while (true) { if (is_palindrome((string) $num)) { return "{$i} {$num}"; } $num = $num + (int) strrev($num); $i++; } }
<?php function is_palindrome(array $s) { $counted_values = array_count_values($s); $count_singles = 0; foreach ($counted_values as $v) { if ($v === 1 || $v % 2 !== 0) { $count_singles++; } if ($count_singles > 1) { return false; } } return true; } $s = str_split(trim(fgets(STDIN))); echo is_palindrome($s) ? 'YES' : 'NO';
/** * @depends testPalindromeloader * @expectedException \InvalidArgumentException */ public function testIsPalindromeException() { is_palindrome([]); }
} } } //Check foo_odd(10, 35); //Task 7 echo '<h1>Task 7</h1>'; function utf8_strrev($str) { preg_match_all('/./us', $str, $ar); return join('', array_reverse($ar[0])); } function is_palindrome($word) { if (is_string($word)) { $word = strtolower($word); $reverse = utf8_strrev($word); if ($word == $reverse) { return true; } else { return false; } } } //Check $word = "raceqcar"; $cheack_polindrom = is_palindrome($word); var_dump($cheack_polindrom); ?>
<?php $pal = 0; for ($a = 999; $a > 99; $a--) { for ($b = 999; $b > 99; $b--) { $num = $a * $b; if (is_palindrome($num) && $num > $pal) { $pal = $num; } } } echo "{$pal}\n"; function is_palindrome($s) { $rev = strrev($s); if (strcmp($rev, $s) == 0) { return true; } else { return false; } }
<?php function is_palindrome($str) { if (strlen($str) <= 1) { return true; } $str_cleaned = preg_replace('/\\s|[[:punct:]]|_/', '', $str); if (strrev($str_cleaned) == $str_cleaned) { return "true"; } else { return "false"; } } function print_r2($val) { echo '<pre>'; print_r($val); echo '</pre>'; } print_r2(is_palindrome("racecar")); print_r2(is_palindrome("rac ecar .")); print_r2(is_palindrome("yolo"));