这是我到目前为止所拥有的:
<?php
$text = preg_replace('/((\*) (.*?)\n)+/', 'awesome_code_goes_here', $text);
?>
我成功匹配以下格式的纯文本列表:
* list item 1
* list item 2
我想将其替换为:
<ul>
<li>list item 1</li>
<li>list item 2</li>
</ul>
我无法绕开<ul>
s <li>
! 有人可以帮忙吗?
编辑:解决方案如下...
我的代码现在是:
$text = preg_replace('/\* (.*?)\n/', '<ul><li>$1</li></ul>', $text);
$text = preg_replace('/<\/ul><ul>/', '', $text);
做到了!