title: PHP Script doesn't work. While Condition inside a Loop
body: <p>I hope somebody can help me here. I am just coding a little bit and I am stuck. A tip would be great, which explains to me, where I am wrong.</p>
  
  <p>The task is kind of more complex, than what I am doing right now. At the moment, I want the for loop to check every substring of a string. Inside the loop is a while condition, which should keep echoing out the substrings, till a substring is a space. Then it should stop echoing out.</p>
  
  <p>I don't understand why it doesn't work. I get a TimeOut on my server.</p>
  
  <pre><code>&lt;?php
  // Task
  // Find-and-Replace
  // "whole word" match
  // Text is sorted as array of character
  
  $text = "This film is the best film of the year."; // Find: film, replace: movie
  $word = "film";
  $replace = "movie";
  echo strlen($text) . "&lt;br&gt;";
  
  for($i = 0; $i &lt;= strlen($text); $i++){
      while(substr($text,$i,1) != " ") {
          echo substr($text,0,1);
      }
  }
  
  
  
  ?&gt;
  </code></pre>
  
  <p>Edit:
  It still does not work:</p>
  
  <pre><code>for($i = 0; $i &lt;= strlen($text); $i++){
      while(substr($text,$i,1) != " ") {
          echo substr($text,$i,1);
      }
  }
  </code></pre>
  
  <p>Without the While loop it iterates through every letter. But it will not work with the whileloop.</p>