Last active
January 3, 2018 09:39
-
-
Save morozVA/28121fee1067d087136dafc15fd565ec to your computer and use it in GitHub Desktop.
evo truncate a long string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/**********Как обрезать длину строки?******************/ | |
[!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