$word = "malayalam";
$pal = true;
for ($i = 0; $i < strlen($word)/2; ++$i, --$j) {
// skip spaces
while ($word[$i] === " ") {$i++;}
while ($word[$j] === " ") {$j--;}
echo "$word[$i]== $word[$j]\n";
if ($word[$i] !== $word[$j]) {
$pal = false;
break;
}
}
if ($pal) print "yes"; else print "no";
JHdvcmQgPSAibWFsYXlhbGFtIjsKCiRqID0gc3RybGVuICgkd29yZCktMTsKJHBhbCA9IHRydWU7Cgpmb3IgKCRpID0gMDsgJGkgPCBzdHJsZW4oJHdvcmQpLzI7ICsrJGksIC0tJGopIHsKCiAgICAvLyBza2lwIHNwYWNlcwogICAgd2hpbGUgKCR3b3JkWyRpXSA9PT0gIiAiKSB7JGkrKzt9CiAgICB3aGlsZSAoJHdvcmRbJGpdID09PSAiICIpIHskai0tO30KCiAgICBlY2hvICIkd29yZFskaV09PSAkd29yZFskal1cbiI7CiAgICBpZiAoJHdvcmRbJGldICE9PSAkd29yZFskal0pICAgIHsKICAgICAgICAkcGFsID0gZmFsc2U7CiAgICAgICAgYnJlYWs7CiAgICAgICAgfQp9CgppZiAoJHBhbCkgcHJpbnQgInllcyI7IGVsc2UgcHJpbnQgIm5vIjsK