目前,我收到了一系列包含所有类型html标签的内容。
我想知道如何将它们分成几列来维护HTML标记,但不允许使用600个字符。
我有以下内容:
$formatedContent = strip_tags($content, '<br><br/><strong><a><ul><li>');
$pages_array = explode(" ",$formatedContent);
$pages_array_split = array();
$letter_count = 0;
$split_start = 0;
foreach($pages_array as $key => $page) {
if($letter_count+strlen($page)+1 > 600) {
$split_point = $letter_count+strlen($page)+1;
array_push($pages_array_split,substr($formatedContent,$split_start,$split_point));
$split_start += $letter_count+strlen($page)+1;
$letter_count = 0;
} else if($key == count($pages_array)-1) {
array_push($pages_array_split,substr($formatedContent,$split_start));
}
$letter_count += strlen($page)+1;
}
$content
var是包含内容的字符串。
现在我有一些问题。
1)有时单词会在中间被破坏(因为我在中间有标签)
2)如果我在一列中有列表,则下一列有点被销毁,因为<li>
不在<ul>
有没有办法关闭标签并在下一栏中打开?有没有办法保证单词不被破坏?
输入示例:
<p><span>Lorem ipsum ipsum<br /></span> <br /> <strong><span style="text-decoration: underline;"><br />Lorem ipsum ipsum<br /><br /></span></strong></p>
<p>Lorem ipsum ipsum</p>
<ul>
<li><span">Lorem ipsum ipsum</span></li>
<li><span">Lorem ipsum ipsum</span></li>
<li><span">Lorem ipsum ipsum</span></li>
<!--Imagine 600 characters till here and it breaks now!-->
<li><span>Lorem ipsum ipsum</span></li>
<li><span>Lorem ipsum ipsum</span></li>
<li><span>Lorem ipsum ipsum.</span></li>
<li><span>Lorem ipsum ipsum</span></li>
<li><span>Lorem ipsum ipsum<br /> <br /><br /></span></li>
</ul>
<p><strong>Lorem ipsum ipsum</strong></p>
<p>Lorem ipsum ipsum<a href="http://www.lorem.org/">www.lorem.org</a><a title="www.lorem.org" href="http://www.lorem.org/">/</a> </p>
<p> </p>
然后输出为:
<div class="col"> //First column
<p>
<span>Lorem ipsum ipsum<br /></span><br />
<strong>
<span style="text-decoration: underline;"><br />Lorem ipsum ipsum<br /><br /></span>
</strong>
</p>
<p>Lorem ipsum ipsum</p>
<ul>
<li><span">Lorem ipsum ipsum</span></li>
<li><span">Lorem ipsum ipsum</span></li>
<li><span">Lorem ipsum ipsum</span></li>
</ul>
</div>
<!--Imagine 600 characters till here and it breaks now!-->
<div class="col"> //Second column
<ul>
<li><span>Lorem ipsum ipsum</span></li>
<li><span>Lorem ipsum ipsum</span></li>
<li><span>Lorem ipsum ipsum.</span></li>
<li><span>Lorem ipsum ipsum</span></li>
<li><span>Lorem ipsum ipsum<br /> <br /><br /></span></li>
</ul>
<p><strong>Lorem ipsum ipsum</strong></p>
<p>Lorem ipsum ipsum<a href="http://www.lorem.org/">www.lorem.org</a><a title="www.lorem.org" href="http://www.lorem.org/">/</a> </p>
<p> </p>
</div>
其余的列继续
这可能吗 ?
如果要做的代码太多,你能告诉我应采取什么方法吗?