Elgg  Version master
excerpt.php
Go to the documentation of this file.
1 <?php
10 $text = (string) elgg_extract('text', $vars);
12 $text = str_replace('&nbsp;', ' ', $text);
13 $text = preg_replace('/ +/', ' ', $text);
14 $text = trim($text);
15 
16 $suffix = elgg_extract('suffix', $vars, '...');
17 
19 $num_chars = (int) elgg_extract('num_chars', $vars, 250);
20 
21 if ($string_length <= $num_chars) {
22  echo $text;
23  return;
24 }
25 
26 // handle cases
29 
30 // don't crop if can't find a space.
31 if ($space === false) {
33 }
34 
35 $excerpt = trim(elgg_substr($excerpt, 0, $space));
36 
38  $excerpt .= $suffix;
39 }
40 
41 echo $excerpt;
$vars
Definition: theme.php:3
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:246
elgg_substr()
Wrapper function for mb_substr().
Definition: mb_wrapper.php:195
elgg_strrpos()
Wrapper function for mb_strrpos().
Definition: mb_wrapper.php:89
elgg_strlen()
Wrapper function for mb_strlen().
Definition: mb_wrapper.php:53
$num_chars
Definition: excerpt.php:19
$space
Definition: excerpt.php:28
$suffix
Definition: excerpt.php:16
if($string_length<=$num_chars) $excerpt
Definition: excerpt.php:27
$string_length
Definition: excerpt.php:18
$text
Output view for elgg_get_excerpt.
Definition: excerpt.php:10
elgg_strip_tags(string $string, ?string $allowable_tags=null)
Strip tags and offer plugins the chance.
Definition: output.php:323