How to check whether a string is palindrome or not in PHP

2 Answers

0 votes
$str = "rotator";
 
if (strcmp($str, strrev($str)) == 0)
    echo "Palindrome";
else
    echo "Not Palindrome";
 
 
 
 
 
/*
run:
 
Palindrome
 
*/

 



answered Aug 23, 2021 by avibootz
edited Jun 20, 2023 by avibootz
0 votes
function is_palindrome($string) {
    $string = strtolower(preg_replace("/[^A-Za-z0-9]/","", $string));

    return $string == strrev($string);
}

$string = "ro.tat#or";

echo is_palindrome($string) ? "yes" : "no";



/*
run:

yes

*/

 



answered Jun 20, 2023 by avibootz

Related questions

1 answer 160 views
1 answer 172 views
1 answer 161 views
1 answer 175 views
2 answers 191 views
4 answers 227 views
...