A regex that converts text lists to html in PHP

后端 未结 4 2123
谎友^
谎友^ 2021-01-05 08:51

I\'m trying to code a regexp to convert a block of text:

* List item
* Another list item

to html:

4条回答
  •  春和景丽
    2021-01-05 08:55

    Well, you could simply do

    $text = "
      " . preg_replace("/\*+(.*)?/i","
    • $1
    • ",$text) . "
    ";

    or, if you really want to use preg_replace

    $text = preg_replace("/(\(.*?)\<\/li\>\n*)+/is","
      \n$1\n
    \n",$text);

提交回复
热议问题