Answers for "php function that accepts a string and check if it is palindrome"

PHP
2

palindrome in php

<?php

function palindrome($input) {
    $middle = strlen($input) / 2;
    $firstHalf = substr($input, 0, floor($middle));
    $secondHalf = substr($input, ceil($middle));
    return $firstHalf == strrev($secondHalf);
}

echo palindrome("racecar") ? "Palindrome" : "Not a palindrome";
Posted by: Guest on May-30-2021

Code answers related to "php function that accepts a string and check if it is palindrome"

Browse Popular Code Answers by Language