【发布时间】:2014-10-08 10:23:50
【问题描述】:
我有一个降价文本内容,我必须在不使用库函数的情况下替换它。所以我为此使用了 preg 替换。它在某些情况下工作正常。对于标题等情况
for eg Heading
=======
should be converted to <h1>Heading</h1> and also
##Sub heading should be converted to <h2>Sub heading</h2>
###Sub heading should be converted to <h3>Sub heading</h3>
我试过了
$text = preg_replace('/##(.+?)\n/s', '<h2>$1</h2>', $text);
上面的代码有效,但我需要计算哈希符号,并基于此分配标题标签。
请大家帮帮我....
【问题讨论】:
标签: php regex preg-replace markdown