title: Ajax responseText and echo broken, returning header file contents
body: <p>I have the following code in my thePhpFile.php file to handle an Ajax call:</p>
  
  <pre><code>&lt;?php
      require_once('usefulStuff.php'); // stuff used throughout the code 
  
  if (isset($_GET['zer']))
  {
  
     $bFound = false;
  
  
    if(! $bFound)
    {
       echo "notfound";
       return;
    }   
    else 
    {
        echo "found";
        return;
    }
  }
  ?&gt;
  </code></pre>
  
  <p>Here's the inline onreadystate function (javascript) that handles the responseText:</p>
  
  <pre><code>var theResponseText = "rText";
  var zer = "testing";
  
  xmlhttp.onreadystatechange = function()
  {
      if(xmlhttp.readyState == 4 &amp;&amp; xmlhttp.status == 200)
      {
          theResponseText = xmlhttp.responseText;
          alert("responseText is &gt;&gt;&gt;" + theResponseText + "&lt;&lt;&lt; that.");
  
          if( theResponseText == 'notfound')
          {
              alert("sorry, nothing found.")
          }
      }
  }
  
  var ajaxText = "thePhpFile.php?zer=" + zer;
  xmlhttp.open("GET", ajaxText, false);
  xmlhttp.send();
  </code></pre>
  
  <p>If I add, say, newlines or anything else, really, in my usefulStuff.php include file -- and I add it at the bottom of usefulStuff.php, <strong>after</strong> the <strong>?></strong> closing tag -- the following line of code from above, an echo statement, goes out of its way to locate and grab those extra newlines, etc. and return them in my responseText:</p>
  
  <pre><code> echo "notfound";
  </code></pre>
  
  <p>Having written a compiler, and dealt with BNF grammars, I don't get why the echo statement in php was set up to 'echo' anything more than what immediately follows the 'echo' up to the first semicolon ';' that is encountered during the parse.</p>
  
  <p>I know I can use trim() to undo the whitespace, but my question is, I want to compel my echo statements above to behave in the manner the echo syntax above suggest it <em>should</em> act.  If there is a good reason why the echo statements above are going around looking for extraneous whitespace in my include files to return with my "notfound" text, I don't know what reason that would be, but I want to disable that unexpected behavior.</p>
  
  <p>I want my line of code  <strong>echo "notfound";</strong> to do that and nothing more -- simply to echo the word <strong>notfound</strong> and to stop echo-ing when the semicolon is encountered immediately after the "notfound" text.   </p>
  
  <p>How can I limit the <strong>echo</strong> behavior to only echo what immediately follows the word <strong>echo</strong> and stops the echo-ing when the semicolon is reached?</p>
  
  <p>By the way, while experimenting with my usefulStuff.php file's contents that fall outside of the <strong>?></strong> termination tag, I added this at the end of that file:</p>
  
  <pre><code> // now ending the php code in usefuleStuff.php:
  ?&gt;
  &lt;noscript&gt;
     &lt;meta http-equiv="refresh" content="0; 
           URL=http://mywebsite.com/noscript.html"/&gt;
  &lt;/noscript&gt;
  </code></pre>
  
  <p>The line of code  <strong>echo "notfound";</strong> -- when I retrieve my responseText -- the response text contains all three <strong>noscript</strong> lines of code also, plus any extra whitespace, in addition to my "notfound".  </p>
  
  <p>So the 'echo' in php is garbage-collecting whatever I put at the end of my included usefulStuff.php file.</p>
  
  <p>How can I limit echo's behavior to do what the line of code <strong>echo "notfound";</strong> leads you to to believe it would do, that is, echo only the word "notfound" ? </p>