Palindrome Program In Php - Php

How to code palindrome program in php?

Snippet Code


  
Rate this page :
  [ 0 votes]

The palindrome is generally a word or phrase which gives same meaning when we read it in forward and backward. Here the function palindrome() is used to find whether the given phrase is palindrome or not.

<?php error_reporting(0); function palindrome($inputstring) { $arr = array(); $arr = str_split($inputstring); $len = sizeof($arr); $newstring = ""; for ($i = $len; $i >= 0; $i--) { $newstring.=$arr[$i]; } if ($inputstring == $newstring) { return $inputstring . " is a palindrome"; } else { return $inputstring . " is not a palindrome"; } } $inputstring = "php"; echo palindrome($inputstring); ?>

Tags


Ask Questions

Ask Question