我有以下的 HTML 语句
[otsection]Wallpapers[/otsection]
WALLPAPERS GO HERE
[otsection]Videos[/otsection]
VIDEOS GO HERE
我想要做的是将[otsection]标记替换为html div。但是有一个问题,我希望将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小时尝试后,我无法让它正常工作。
非常感谢任何对此提供帮助的人!
i
是一个标志,使其不区分大小写。s
允许.
匹配换行符。 - Niet the Dark Absoleval
更大;) - Niet the Dark Absolfunction_create()
而不是匿名函数,仍然会存在eval()
问题。而上面的示例显示了function_create()
,这就是为什么我要发出警告的原因。 - Michael Probst