title: PHP: Skip/Remove lines starting with ###
body: <p>I need to be able to skip the first 20 lines from a file that start with a ###. (Actually 18 lines start with ### and two start with ;).</p>
  
  <p>Everything I've tried fails to skip the same two lines – I have no clue why.</p>
  
  <p>Here's what I've tried (this is only the relevant part of my code):</p>
  
  <pre><code>elseif($sourceformat == "Babylon") {
  
      $line = fgets($source_file);
      if($line[0] === '#') {
          continue;
      }
      if(strpos(trim($line), '#') === 0) {
          continue;
      }
      if(substr($line, 0, 1) == "#") {
          continue;
      }
  
      $source = trim(fgets($source_file));
  
      if(empty($source)) {
          continue;
      }
  
      $target = trim(fgets($source_file));
  }
  // then I proceed to writing the extracted terms into a new file that has a different format.
  </code></pre>
  
  <p>I've tried the three approaches above separately and all together (<code>$line[0] === '#'</code> and <code>strpos(trim($line), '#')</code> and <code>substr($line, 0, 1) == '#')</code> – but the same line is always skipped (undetected). Here's what the whole header section looks like (this is the header of a Babylon glossary file (.gls – but plain text).</p>
  
  <pre><code>### Glossary title:Cheeseus Muzik
  ### Author:Cheeseus
  ### Description:English - Bulgarian and Bulgarian - English glossary of musical terms
  ### Source language:Bulgarian
  ### Source alphabet:Cyrillic
  ### Target language:Bulgarian
  ### Target alphabet:Cyrillic
  ### Icon:
  ### Browsing enabled?Yes
  ### Type of glossary:00000000
  ### Case sensitive words?0
  ; DO NOT EDIT THE NEXT **SIX** LINES  - Babylon-Builder generated text !!!!!!
  ### Glossary id:0265922f91878d6e846e9c869d8a89447c6e719e8585886b8692955f91887a9b8474859a85616a279a929ca07f6881507056895d6881304b5142515f42ba6c992e2b23828188719469656840908429504d595b486965418931312d5b47ad7843525650833a233a47514270695543449f31373b7179484e435a8c428827
  ### Confirmation string:8A148GOK
  ### File build number:0121DA07
  ### Build:80"0)2"0
  ### Glossary settings:00000000
  ### Gls type:00000001
  ; DO NOT EDIT THE PREVIOUS **SIX** LINES  - Babylon-Builder generated text !!!!!!
  
  ### Glossary section:
  
  a piacere
  а пиачере, по желание
  
  a tempo
  а темпо, завръщане към основното темпо след отклонение
  
  ad libitum
  ат либитум, свободно, по желание
  
  adagio
  адажио (бавно)
  
  allargando
  аларгандо, забавяне
  
  allegretto
  алегрето, весело, бързичко
  
  allegro
  алегро, бързо, весело
  
  allentando
  алентандо, със забавяне
  
  ... (this is the actual glossary – source term on one line, target term on the next, followed by an empty line, then again source term, target term, new line. I only want these lines, while discarding (omitting, removing) the glossary header lines above. The code I have successfully removes all lines starting with # but this one below (the glossary ID), and it also removes the two lines starting with a semi-colon.
  </code></pre>
  
  <p>This is the line I can't seem to get rid of:</p>
  
  <pre><code>### Glossary id:0265922f91878d6e846e9c869d8a89447c6e719e8585886b8692955f91887a9b8474859a85616a279a929ca07f6881507056895d6881304b5142515f42ba6c992e2b23828188719469656840908429504d595b486965418931312d5b47ad7843525650833a233a47514270695543449f31373b7179484e435a8c428827
  </code></pre>
  
  <p>I suspect this is because this line is quite long (or could it be because the preceding line starts with a semi-colon?). I've tried specifying the max. byte-length for each line being read in <code>fgets</code>:</p>
  
  <pre><code>$line = fgets($source_file, 8192);
  </code></pre>
  
  <p>But this didn't work either. Hope you can help.</p>
  
  <p>The whole code is too long to put here and it is already working just fine – except for getting rid of this single line.</p>
  
  <p><strong>SOLUTION (based on @Mehdi Bounya's answer)</strong></p>
  
  <p>It seems I wasn't performing the checks I already had in place in the correct place. Here's the code that does exactly what I need:</p>
  
  <pre><code>elseif($sourceformat == "Babylon") {
  
      if($targetformat == "Wordfast") {
          $converted_source_target_delimiter = "\t";
          $converted_term_delimiter = "\r\n";
      }
  
      $source = trim(fgets($source_file));
  
      if(empty($source)) {
          continue;
      }
      if($source[0] === '#') {
          continue;
      }
      if($source[0] === ';') {
          continue;
      }
  
      $target = trim(fgets($source_file));
  }
  $exported_entry = $source.$converted_source_target_delimiter.$target.$converted_term_delimiter;
  </code></pre>
  
  <p><em>Thank you to everyone who offered help!</em></p>