PEEL Shopping
Open source ecommerce : PEEL Shopping
modifier.truncate.php
Go to the documentation of this file.
1 <?php
27 function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_words = false, $middle = false) {
28  if ($length == 0)
29  return '';
30 
31  if (Smarty::$_MBSTRING) {
32  if (mb_strlen($string, Smarty::$_CHARSET) > $length) {
33  $length -= min($length, mb_strlen($etc, Smarty::$_CHARSET));
34  if (!$break_words && !$middle) {
35  $string = preg_replace('/\s+?(\S+)?$/' . Smarty::$_UTF8_MODIFIER, '', mb_substr($string, 0, $length + 1, Smarty::$_CHARSET));
36  }
37  if (!$middle) {
38  return mb_substr($string, 0, $length, Smarty::$_CHARSET) . $etc;
39  }
40  return mb_substr($string, 0, $length / 2, Smarty::$_CHARSET) . $etc . mb_substr($string, - $length / 2, $length, Smarty::$_CHARSET);
41  }
42  return $string;
43  }
44 
45  // no MBString fallback
46  if (isset($string[$length])) {
47  $length -= min($length, strlen($etc));
48  if (!$break_words && !$middle) {
49  $string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length + 1));
50  }
51  if (!$middle) {
52  return substr($string, 0, $length) . $etc;
53  }
54  return substr($string, 0, $length / 2) . $etc . substr($string, - $length / 2);
55  }
56  return $string;
57 }
58 
59 ?>
static $_UTF8_MODIFIER
Flag denoting if PCRE should run in UTF-8 mode.
static $_MBSTRING
Flag denoting if Multibyte String functions are available.
smarty_modifier_truncate($string, $length=80, $etc= '...', $break_words=false, $middle=false)
Smarty truncate modifier plugin.
static $_CHARSET
The character set to adhere to (e.g.

This documentation for Open ecommerce PEEL Shopping and PEEL.fr has been generated by Doxygen on Thu Oct 15 2015 14:41:16 - Peel ecommerce is a product of Agence web Advisto SAS. All rights reserved.