這是我到目前爲止有:PHP的preg_replace()上的多個項目
<?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>
並通過<li>
循環小號!任何人都可以幫忙嗎?
編輯:解決方案如下回答...
我的代碼,原先爲:
$text = preg_replace('/\* (.*?)\n/', '<ul><li>$1</li></ul>', $text);
$text = preg_replace('/<\/ul><ul>/', '', $text);
這做到了!
這樣做,謝謝!用新代碼更新的問題 – 2009-08-09 22:41:25