title: Testing for a backslash in a string
body: <p>So I'm writing a PHP script that will read in a CSS file, then put the comments and actual CSS in separate arrays. The script will then build a page with the CSS and comments all nicely formatted. </p>
  
  <p>The basic logic for the script is this:</p>
  
  <ul>
  <li>Read in a new line</li>
  <li>If it starts with a forward slash or
  ends with an opening bracket, set a
  bool for CSS or comments to true</li>
  <li>Add that line to the appropriate
  element in the appropriate array</li>
  <li>If the last character is a backslash
  (end of a comment) or the first
  character is a closing bracket (end
  of a CSS tag), set necessary bool to
  false</li>
  <li>Rinse, repeat</li>
  </ul>
  
  <p>If someone sees an error in that, feel free to point it out, but I think it should do what I want.</p>
  
  <p>The tricky part is the last if statement, checking if the last character is a backslash. Right now I have:</p>
  
  <pre><code>if ($line{(strlen($line) - 3)} == "\\") {do stuff}
  </code></pre>
  
  <p>where $line is the last line read in from the file. Not entirely sure why I have to go back 3 characters, but I'm guessing it's because there's a newline at the end of each string when reading it in from a file. However, this if statement is never true, even though there are definitely lines which end with slashes. This</p>
  
  <pre><code>echo "&lt;br /&gt;str - 3: " . $line{(strlen($line)-3)};
  </code></pre>
  
  <p>even returns a backslash, yet the if statement is never trigged.</p>