How do I truncate an HTML string without breaking the HTML code? I am using following code but it is not working.
<?php
$title ="<div class='links'>I've tried the <b>other examples</b> above and they did not produce the desired results.
<ul>
<b>
<li>lorem ispum</li>
<li>lorem ispum</li>
<li>lorem ispum</li>
</b>
</ul>
<h1>Heading1</h1>
<div class='links'>
<h2>heading2</h2>
<span>loremispum dollar sit amet.</span>
</div>
</div>";
$text = substr( $title, 0, strpos($title, ' ', 105) );
echo $text;
?>
<div>Some Text Goes here</div>
我想知道您是否需要保留HTML格式,还是应该先剥离HTML标记,然后再创建一个子字符串。. 从php字符串中删除所有html标记
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.