<form method=POST action='' name=form1>
<input type=text name=t1 class='form-control' value='$t1' >
<input type=submit value='Check String'>
</form>
<?Php
$t1=$_POST['t1']; // Using POST method of a FORM
//$t1='madam'; // String variable with data for testing
if(strlen($t1) >0){
if($t1==strrev($t1)){ // change this line for case insensitive
echo "<i>$t1</i> is a Palindrome ";
}else{
echo "<i>$t1</i> is NOT a Palindrome ";
}
}else{echo "Enter any string"; }
?>
if(strtolower($t1)==strtolower(strrev($t1))){
<?php
$t1='racecar'; // sample string, change this data
$length=strlen($t1); // length of the string
$t1_reverse=''; // to hold the revesed string
for($i=$length-1;$i>=0;$i--){
$t1_reverse .=$t1[$i];
}
if($t1_reverse==$t1){
echo "<i>$t1</i> is a Palindrome ";
}else{
echo "<i>$t1</i> is NOT a Palindrome ";
}
?>
<?php
$t1=$t2=1234321; // keeping in two variables
$t1_reverse=0;
while($t1>0){
$d=$t1%10; // reminder of division
$t1_reverse = $t1_reverse * 10 + $d;
$t1=floor($t1/10); // floor value
}
//echo $t1_reverse;
if($t1_reverse==$t2){
echo "<i>$t2</i> is a Palindrome ";
}else{
echo "<i>$t2</i> is NOT a Palindrome ";
}
?>
Output
1234321 is a Palindrome
Introduction to PHP Printing output by ECHO command
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.