fork download
  1. $word = "malayalam";
  2.  
  3. $j = strlen ($word)-1;
  4. $pal = true;
  5.  
  6. for ($i = 0; $i < strlen($word)/2; ++$i, --$j) {
  7.  
  8. // skip spaces
  9. while ($word[$i] === " ") {$i++;}
  10. while ($word[$j] === " ") {$j--;}
  11.  
  12. echo "$word[$i]== $word[$j]\n";
  13. if ($word[$i] !== $word[$j]) {
  14. $pal = false;
  15. break;
  16. }
  17. }
Success #stdin #stdout 0.03s 25352KB
stdin
Standard input is empty
stdout
$word = "malayalam";

$j = strlen ($word)-1;
$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;
        }
}