fork download
  1. <?php
  2.  
  3. //$re = "/^(-\\w+\\s*.*)\\n*$/um";
  4. $re = "/^(\\h*(?:-|&)\\h*\w+\\s*.*)\\n*$/um";
  5. $str = "-Give on result\n-Second new text\n-The third text\n\nAnother paragraph without list.\n\n-New list here";
  6. preg_match_all($re, $str, $matches);
  7. echo "<pre>";
  8. print_r($matches);
  9. echo "</pre>";
  10. $i = 0;
  11.  
  12.  
  13. echo "<ul>".preg_replace_callback($re,function($mt){return "<li>".$mt[1]."</li>";},$str)."</ul>";
  14.  
  15.  
Success #stdin #stdout 0.02s 24400KB
stdin
Standard input is empty
stdout
<pre>Array
(
    [0] => Array
        (
            [0] => -Give on result
            [1] => -Second new text
            [2] => -The third text

            [3] => -New list here
        )

    [1] => Array
        (
            [0] => -Give on result
            [1] => -Second new text
            [2] => -The third text
            [3] => -New list here
        )

)
</pre><ul><li>-Give on result</li>
<li>-Second new text</li>
<li>-The third text</li>
Another paragraph without list.

<li>-New list here</li></ul>