Skip to content

Instantly share code, notes, and snippets.

@morozVA
Last active January 3, 2018 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save morozVA/28121fee1067d087136dafc15fd565ec to your computer and use it in GitHub Desktop.
Save morozVA/28121fee1067d087136dafc15fd565ec to your computer and use it in GitHub Desktop.
evo truncate a long string
/**********Как обрезать длину строки?******************/
[!truncate? &text=[*pagetitle*] &len=200!] // в документе MODx
<?php
$lenf = $len;
$order = array("\r\n", "\n", "\r");
$replace = '<br />';
$what = str_replace($order, $replace, $text);
if (strlen($what) > $lenf) {
$what = preg_replace('/^(.{' . $lenf . ',}? ).*$/is', '$1', $what) . '...';
}
return $what;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment