Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save CB9TOIIIA/b0ebefb985c3658885c67b47e6f32df4 to your computer and use it in GitHub Desktop.
Save CB9TOIIIA/b0ebefb985c3658885c67b47e6f32df4 to your computer and use it in GitHub Desktop.
Ограничение количества вводимых символов
<?php
$desc = JString::trim(strip_tags($this->renderPosition('<ИМЯ ПОЗИЦИИ В ШАБЛОНЕ>')));
$descArr = explode(' ', $desc);
$descArr_tmp = array();
foreach ($descArr as $word) {
$word = JString::trim($word);
if ($word) {
$descArr_tmp[] = $word;
}
}
if (count($descArr_tmp) > 40) {
$descArr_tmp = array_slice($descArr_tmp, 0, 40); // 40 - это кол-во слов
echo implode(' ', $descArr_tmp). ' ...';
} else {
echo implode(' ', $descArr_tmp);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment