【发布时间】:2012-06-24 03:46:47
【问题描述】:
我有以下 HTML 语句
[otsection]Wallpapers[/otsection]
WALLPAPERS GO HERE
[otsection]Videos[/otsection]
VIDEOS GO HERE
我想要做的是用 html div 替换 [otsection] 标签。问题是我想将 div 的 id 从 1->2->3 等递增。
所以比如上面的语句应该翻译成
<div class="otsection" id="1">Wallpapers</div>
WALLPAPERS GO HERE
<div class="otsection" id="2">Videos</div>
VIDEOS GO HERE
据我所知,最好的方法是通过 preg_replace_callback 在每次替换之间增加 id 变量。但经过 1 小时的工作后,我无法让它工作。
对此的任何帮助将不胜感激!
【问题讨论】:
标签: php preg-replace preg-replace-callback