title: Matching end of line position using m flag with different line ending styles
body: <p>I'm trying to wrap each line that starts with "## " with tags. Trying to achieve a GitHub/Stackoverflow-like syntax for text formatting.</p>
  
  <p>This is what I got:</p>
  
  <pre><code>$value = preg_replace('/^## (.*)$/m', '&lt;p&gt;$1&lt;/p&gt;', $value);
  </code></pre>
  
  <p>After googling for quite a while this seems the right solution, however it doesn't work as expected or I just don't understand something.</p>
  
  <p>Example text:</p>
  
  <pre><code>## Some header 1
  
  Some text that doesn't need to be altered
  
  ## Some header 2
  </code></pre>
  
  <p>And this is the result:</p>
  
  <pre><code>&lt;p&gt;Some header 1
  &lt;/p&gt;
  
  Some text that doesn't need to be altered
  
  &lt;p&gt;Some header 2&lt;/p&gt;
  </code></pre>
  
  <p>As you can see, the second header gets processed fine as it's at the end of the text. The first header, however, gets an extra new line at the end before the closing tag. How do I get rid of that?</p>