Я пытаюсь отрезать текст после 236 символов без сокращения слов пополам и сохранения html-тегов. Это то, что я использую прямо сейчас:
$shortdesc = $_helper->productAttribute($_product, $_product->getShortDescription(), 'short_description');
$lenght = 236;
echo substr($shortdesc, 0, strrpos(substr($shortdesc, 0, $lenght), " "));
Пока это работает в большинстве случаев, он не будет уважать теги html. Так, например, этот текст:
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. <strong>Stet clita kasd gubergren</strong>
будет отключен, пока тег остается открытым. Есть ли способ отрезать текст после 236 символов, но уважать теги html?