PHP 7 Script to Check Input String is Palindrome or Not Full Tutorial For Beginners

PHP 7 Script to Check Input String is Palindrome or Not Full Tutorial For Beginners
  • Post author:
  • Post category:PHP
  • Post comments:0 Comments

 

Welcome folks today in this blog post we will be looking at how to implement palindrome string check in php. All the full source code of application is shown below.

 

 

Get Started

 

 

In order to get started you need to create an index.php file and copy paste the following code

 

index.php

 

<?php 
// A recursive php program to 
// check whether a given number 
// is palindrome or not 


// A recursive function that 
// check a str[s..e] is 
// palindrome or not. 
function isPalRec($str, $s,$e) 
{ 
    // If there is only one character 
    if ($s == $e) 
    return true; 

    // If first and last 
    // characters do not match 
    if ($str[$s] != $str[$e]) 
    return false; 

    // If there are more than two 
    // characters, check if middle 
    // substring is also palindrome or not. 
    if ($s < $e + 1) 
    return isPalRec($str, $s + 1, $e - 1); 

    return true; 
} 

function isPalindrome($str) 
{ 
$n = strlen($str); 

// An empty string is 
// considered as palindrome 
if ($n == 0) 
    return true; 

return isPalRec($str, 0, $n - 1); 
} 

// Driver Code 
{ 
    $str = "geeg"; 

    if (isPalindrome($str)) 
    echo("Yes"); 
    else
    echo("No"); 

    return 0; 
} 

// This code is contributed 
// by nitin mittal. 
?>

 

See also  PHP 7 Script to Find MAC Address of a Device Using System Command in Browser Full Project For Beginners

And now if you open this php file inside the browser you will see the following output

 

Leave a Reply