当出现特定变量时,我需要将我的html
分成两部分。拆分时动态重建html标记
下面是一个例子:
<h1>I can have any kind of text here</h1>
<p> </p>
<p><em><strong>When I see this variable :)</strong> I want to rebuild my html.</em></p>
我想在最后什么:
<h1>I can have any kind of text here</h1>
<p> </p>
<p><em><strong>When I see this</strong></em></p>
<p><em><strong> :)</strong> I want to rebuild my html.</em></p>
这是我想(告诉我,如果有更好的方法):
- 在我的变量上分割
- 通过正则表达式获取所有标记? (我只是知道正则表达式来告诉我是真是假)
- 把所有的标签都放在堆栈上?
- 循环两次(阵列分割1和阵列分开2)
EDIT实施例2:
<ol>
<li>
<h2>I can have any kind of text here 1</h2>
</li>
<li>
<h2><strong>I can have any kind of text here 2 variable</strong></h2>
</li>
<li>
<h2><strong>I can have any kind of text here 3</strong></h2>
</li>
<li>
<h2>I can have any kind of text here 4</h2>
</li>
<li><em><strong>When I see this</strong></em></li>
</ol>
<p> </p>
...
<ol>
<li>
<h2>I can have any kind of text here 1</h2>
</li>
<li>
<h2><strong>I can have any kind of text here 2 variable </strong></h2>
</li>
</ol>
可变
<ol>
<li>
<h2><strong>I can have any kind of text here 3</strong></h2>
</li>
<li>
<h2>I can have any kind of text here 4</h2>
</li>
<li><em><strong>When I see this</strong></em></li>
</ol>
<p> </p>
为例3:
<p><a href="test">I can have any kind of text of varaible here even clickable.</a></p>
...
<p><a href="test">I can have any kind of text of</a></p>
varaible
<p><a href="test">here even clickable.</a></p>
第5步:忘记第1步 - 4并改用解析器? – Jan
的确有很多html解析器。 –