Hello !
I have a small snippet that works pretty well, I use it to truncate my "summary" fields (the snippet call is in a chunk - for my frontpage news)
And I realize that it might serve other people and be available to download in snippet section.
The only thing I do not understand is that during a call, if special characters such as "?" or ":" is in my field summary the snippet completely bug
Does anyone could help me?
Here is the snippet + the call I use:
[[truncate? &what=`[+summary+]` &len=`700`]]
<?php
/* ----------
parameters:
$what - text to shorten
$len - desired length of the shortened text
---------- */
if (strlen($what) > $len) {
/* there is a point to truncate */
$what = preg_replace('/^(.{' . $len . ',}? ).*$/is', '$1', $what) . '...';
}
return $what;
?>