title: Remove repeating character
body: <p>How would I remove repeating characters (e.g. remove the letter <code>k</code> in <code>cakkkke</code> for it to be <code>cake</code>)?</p>
  
  <p>One straightforward way to do this would be to loop through each character of the string and append each character of the string to a new string if the character isn't a repeat of the previous character.</p>
  
  <p>Here is some code that can do this:</p>
  
  <pre><code>$newString = '';
  $oldString = 'cakkkke';
  $lastCharacter = '';
  for ($i = 0; $i &lt; strlen($oldString); $i++) {
      if ($oldString[$i] !== $lastCharacter) {
          $newString .= $oldString[$i];
      }
      $lastCharacter = $oldString[$i];
  }
  echo $newString;
  </code></pre>
  
  <p>Is there a way to do the same thing more concisely using regex or built-in functions?</p>