title: Ruby gsub to PHP. Change the behavior of markdown
body: <p>I am trying to change the default behavior of <a href="http://daringfireball.net/projects/markdown/" rel="nofollow noreferrer">Markdown</a> where single line breaks are <em>not</em> converted to <code>&lt;br /&gt;</code>. </p>
  
  <p>I found that <a href="http://github.github.com/github-flavored-markdown/" rel="nofollow noreferrer">github flavored markdown</a> does this, but I am having a hard time converting the rube gsub function to something similar in PHP. </p>
  
  <p>The Ruby code looks like this:</p>
  
  <pre><code>text.gsub!(/(\A|^$\n)(^\w[^\n]*\n)(^\w[^\n]*$)+/m) do |x|
     x.gsub(/^(.+)$/, "\\1  ")
  end
  </code></pre>
  
  <p>But even that I try this simple approach in PHP I see no difference</p>
  
  <pre><code>$text = preg_replace("/^(.+)$/", "\\1", $text);
  $text = Markdown($text);
  </code></pre>
  
  <p>Any help in the conversion from Ruby to PHP will be highly appreciated.</p>
  
  <p>PS. No need for discussion of the behavior in general here, please see the meta question <a href="https://meta.stackexchange.com/questions/26011/should-the-markdown-renderer-treat-a-single-line-break-as-br">should the markdown renderer treat a single line break as br</a></p>