Source code for file /pattemplate/patTemplate/Modifier/Truncate.php
Documentation is available at Truncate.php
* patTemplate modifier Truncate
* Truncate a string variable to fixed length and add a suffix if it was truncated.
* It can also start from an offset and add a prefix.
// Check to ensure this file is within the rest of the framework
* patTemplate modifier Truncate
* Truncate a string variable to fixed length and add a suffix if it was truncated.
* It can also start from an offset and add a prefix.
* Possible attributes are:
* @return string modified value
function modify($value, $params =
array())
if (!isset
( $params['length'])) {
settype($params['length'], 'integer');
$decode = isset
( $params['htmlsafe'] );
if (isset
($params['start'])) {
settype( $params['start'], 'integer' );
if (isset
($params['prefix'])) {
$prefix =
($params['start'] ==
0 ?
'' :
$params['prefix']);
if (isset
($params['suffix'])) {
$suffix =
$params['suffix'];
$initial_len =
strlen($value);
$value =
substr($value, $params['start'], $params['length']);
if ($initial_len <=
strlen($value)) {
$value =
$prefix.
$value.
$suffix;