title: PHP beginner palindrome script
body: <p>I was working on (for fun) writing a script that would recognize palindromes. So far, I'm successful with "Kayak", "Racecar", "Anna", "A man a plan a canal Panama": yet variations on the latter phrase such as "amanaplana canalpan ama" gives me problems. </p>
  
  <p><em>As a side note:</em> I do understand that using PCRE would make things a lot easier for me, but I'm not fluent in it and one of my major aims was to understand the algorithm behind checking for palindromes.</p>
  
  <pre><code> &lt;?php
  $word = "amanaplana canalpan ama";
  
  $space = " ";
  $word_smallcase = strtolower($word);        
  
  $word_array = str_split($word_smallcase);   
  
  if(in_array($space, $word_array)){      
  
      for($m = 0; $m&lt;count($word_array); $m = $m + 1){
          if($word_array[$m] == $space)
              unset($word_array[$m]);
      }
  }
  $count = 0;
  $scan_count = -1;
  for($i = 0; $i &lt; (count($word_array)/2); $i = $i + 1){
  
      for($j = count($word_array); $j &gt; (count($word_array)/2); $j = $j - 1){
  
          if($word_array[$i]==$word_array[$j]){
              $count = $count + 1;
              break;
              }
          }
      $scan_count = $scan_count + 1;
  
          }
  if ($count == $scan_count){
      echo $word." is a palindrome";
  }
  else{
  
      echo $word ." is NOT a palindrome";
  }
  
  
  ?&gt;
  </code></pre>
  
  <p>I'd appreciate a response regarding:</p>
  
  <ul>
  <li>The identification of the bug I'm having.  </li>
  <li>Recommendations as to
  how I could possibly improve the code (I'd be happy if I could make
  things work without resorting to $count or $scan_count which seem, to
  my eye, relatively amateurish).</li>
  </ul>
  
  <p>Thanks in advance.</p>