Find Palindrom In PHP


  1. Input String
  2. Max string 2^63
  3. Check String Palindrome or Not Palindrome


palindromnot palindrom

Source palindrom.php

<title>Find Palindrome</title>
<h2>Find Palindrome </h2>
<form action=”” method=”post”>
<label>Enter a word or a sentence<label>
<input type=”text” name=”string” />
<input type=”submit” value=”Submit”/>

$string = $_POST[‘string’];

//remove all spaces
$string = str_replace(‘ ‘, ”, $string);

//remove special characters
$string = preg_replace(‘/[^A-Za-z0-9\-]/’, ”, $string);

//change case to lower
$string = strtolower($string);

//calculate string length
$strlength = strlen($string);
echo ‘Characters = ‘;
echo $strlength;

//reverse character
$reverse = strrev($string);

//max character = 2 pangkat 63 (9223372036854775808)
if(strlen($string) >= 9223372036854775808){
echo ‘<br><b>Max Characters >= 9223372036854775808)’;

//check palindrome
}elseif($string == $reverse){
echo “<p><b>It is Palindrome</p>”;
echo “</p><b>Not Palindrome</p>”;


Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:


You are commenting using your account. Logout /  Ubah )

Foto Google+

You are commenting using your Google+ account. Logout /  Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout /  Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout /  Ubah )


Connecting to %s