blob: 9194b577d5166f41c8739bc4215e45f45fb2fba4 [file] [log] [blame]
Derek Allard2067d1a2008-11-13 22:59:24 +00001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2/**
3 * CodeIgniter
4 *
Greg Aker741de1c2010-11-10 14:52:57 -06005 * An open source application development framework for PHP 5.1.6 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
7 * @package CodeIgniter
8 * @author ExpressionEngine Dev Team
Derek Jones7f3719f2010-01-05 13:35:37 +00009 * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
Derek Allard2067d1a2008-11-13 22:59:24 +000010 * @license http://codeigniter.com/user_guide/license.html
11 * @link http://codeigniter.com
12 * @since Version 1.0
13 * @filesource
14 */
15
16// ------------------------------------------------------------------------
17
18/**
19 * CodeIgniter Text Helpers
20 *
21 * @package CodeIgniter
22 * @subpackage Helpers
23 * @category Helpers
24 * @author ExpressionEngine Dev Team
25 * @link http://codeigniter.com/user_guide/helpers/text_helper.html
26 */
27
28// ------------------------------------------------------------------------
29
30/**
31 * Word Limiter
32 *
33 * Limits a string to X number of words.
34 *
35 * @access public
36 * @param string
37 * @param integer
38 * @param string the end character. Usually an ellipsis
39 * @return string
Barry Mienydd671972010-10-04 16:33:58 +020040 */
Derek Allard2067d1a2008-11-13 22:59:24 +000041if ( ! function_exists('word_limiter'))
42{
43 function word_limiter($str, $limit = 100, $end_char = '&#8230;')
44 {
45 if (trim($str) == '')
46 {
47 return $str;
48 }
Barry Mienydd671972010-10-04 16:33:58 +020049
Derek Allard2067d1a2008-11-13 22:59:24 +000050 preg_match('/^\s*+(?:\S++\s*+){1,'.(int) $limit.'}/', $str, $matches);
Barry Mienydd671972010-10-04 16:33:58 +020051
Derek Allard2067d1a2008-11-13 22:59:24 +000052 if (strlen($str) == strlen($matches[0]))
53 {
54 $end_char = '';
55 }
Barry Mienydd671972010-10-04 16:33:58 +020056
Derek Allard2067d1a2008-11-13 22:59:24 +000057 return rtrim($matches[0]).$end_char;
58 }
59}
Barry Mienydd671972010-10-04 16:33:58 +020060
Derek Allard2067d1a2008-11-13 22:59:24 +000061// ------------------------------------------------------------------------
62
63/**
64 * Character Limiter
65 *
66 * Limits the string based on the character count. Preserves complete words
67 * so the character count may not be exactly as specified.
68 *
69 * @access public
70 * @param string
71 * @param integer
72 * @param string the end character. Usually an ellipsis
73 * @return string
Barry Mienydd671972010-10-04 16:33:58 +020074 */
Derek Allard2067d1a2008-11-13 22:59:24 +000075if ( ! function_exists('character_limiter'))
76{
77 function character_limiter($str, $n = 500, $end_char = '&#8230;')
78 {
79 if (strlen($str) < $n)
80 {
81 return $str;
82 }
Barry Mienydd671972010-10-04 16:33:58 +020083
Derek Allard2067d1a2008-11-13 22:59:24 +000084 $str = preg_replace("/\s+/", ' ', str_replace(array("\r\n", "\r", "\n"), ' ', $str));
85
86 if (strlen($str) <= $n)
87 {
88 return $str;
89 }
Barry Mienydd671972010-10-04 16:33:58 +020090
Derek Allard2067d1a2008-11-13 22:59:24 +000091 $out = "";
92 foreach (explode(' ', trim($str)) as $val)
93 {
Derek Jones01d6b4f2009-02-03 14:51:00 +000094 $out .= $val.' ';
Barry Mienydd671972010-10-04 16:33:58 +020095
Derek Allard2067d1a2008-11-13 22:59:24 +000096 if (strlen($out) >= $n)
97 {
Derek Jones01d6b4f2009-02-03 14:51:00 +000098 $out = trim($out);
99 return (strlen($out) == strlen($str)) ? $out : $out.$end_char;
Barry Mienydd671972010-10-04 16:33:58 +0200100 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000101 }
102 }
103}
Barry Mienydd671972010-10-04 16:33:58 +0200104
Derek Allard2067d1a2008-11-13 22:59:24 +0000105// ------------------------------------------------------------------------
106
107/**
108 * High ASCII to Entities
109 *
110 * Converts High ascii text and MS Word special characters to character entities
111 *
112 * @access public
113 * @param string
114 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200115 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000116if ( ! function_exists('ascii_to_entities'))
117{
118 function ascii_to_entities($str)
119 {
Barry Mienydd671972010-10-04 16:33:58 +0200120 $count = 1;
121 $out = '';
122 $temp = array();
123
124 for ($i = 0, $s = strlen($str); $i < $s; $i++)
125 {
126 $ordinal = ord($str[$i]);
127
128 if ($ordinal < 128)
129 {
Derek Jones1978e122009-02-03 14:54:43 +0000130 /*
131 If the $temp array has a value but we have moved on, then it seems only
132 fair that we output that entity and restart $temp before continuing. -Paul
133 */
134 if (count($temp) == 1)
135 {
136 $out .= '&#'.array_shift($temp).';';
137 $count = 1;
138 }
Barry Mienydd671972010-10-04 16:33:58 +0200139
Derek Jones1978e122009-02-03 14:54:43 +0000140 $out .= $str[$i];
Barry Mienydd671972010-10-04 16:33:58 +0200141 }
142 else
143 {
144 if (count($temp) == 0)
145 {
146 $count = ($ordinal < 224) ? 2 : 3;
147 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000148
Barry Mienydd671972010-10-04 16:33:58 +0200149 $temp[] = $ordinal;
Derek Allard2067d1a2008-11-13 22:59:24 +0000150
Barry Mienydd671972010-10-04 16:33:58 +0200151 if (count($temp) == $count)
152 {
153 $number = ($count == 3) ? (($temp['0'] % 16) * 4096) + (($temp['1'] % 64) * 64) + ($temp['2'] % 64) : (($temp['0'] % 32) * 64) + ($temp['1'] % 64);
154
155 $out .= '&#'.$number.';';
156 $count = 1;
157 $temp = array();
158 }
159 }
160 }
161
162 return $out;
Derek Allard2067d1a2008-11-13 22:59:24 +0000163 }
164}
Barry Mienydd671972010-10-04 16:33:58 +0200165
Derek Allard2067d1a2008-11-13 22:59:24 +0000166// ------------------------------------------------------------------------
167
168/**
169 * Entities to ASCII
170 *
171 * Converts character entities back to ASCII
172 *
173 * @access public
174 * @param string
175 * @param bool
176 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200177 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000178if ( ! function_exists('entities_to_ascii'))
179{
180 function entities_to_ascii($str, $all = TRUE)
181 {
Barry Mienydd671972010-10-04 16:33:58 +0200182 if (preg_match_all('/\&#(\d+)\;/', $str, $matches))
183 {
184 for ($i = 0, $s = count($matches['0']); $i < $s; $i++)
185 {
186 $digits = $matches['1'][$i];
Derek Allard2067d1a2008-11-13 22:59:24 +0000187
Barry Mienydd671972010-10-04 16:33:58 +0200188 $out = '';
Derek Allard2067d1a2008-11-13 22:59:24 +0000189
Barry Mienydd671972010-10-04 16:33:58 +0200190 if ($digits < 128)
191 {
192 $out .= chr($digits);
Derek Allard2067d1a2008-11-13 22:59:24 +0000193
Barry Mienydd671972010-10-04 16:33:58 +0200194 }
195 elseif ($digits < 2048)
196 {
197 $out .= chr(192 + (($digits - ($digits % 64)) / 64));
198 $out .= chr(128 + ($digits % 64));
199 }
200 else
201 {
202 $out .= chr(224 + (($digits - ($digits % 4096)) / 4096));
203 $out .= chr(128 + ((($digits % 4096) - ($digits % 64)) / 64));
204 $out .= chr(128 + ($digits % 64));
205 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000206
Barry Mienydd671972010-10-04 16:33:58 +0200207 $str = str_replace($matches['0'][$i], $out, $str);
208 }
209 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000210
Barry Mienydd671972010-10-04 16:33:58 +0200211 if ($all)
212 {
213 $str = str_replace(array("&amp;", "&lt;", "&gt;", "&quot;", "&apos;", "&#45;"),
214 array("&","<",">","\"", "'", "-"),
215 $str);
216 }
217
218 return $str;
Derek Allard2067d1a2008-11-13 22:59:24 +0000219 }
220}
Barry Mienydd671972010-10-04 16:33:58 +0200221
Derek Allard2067d1a2008-11-13 22:59:24 +0000222// ------------------------------------------------------------------------
223
224/**
225 * Word Censoring Function
226 *
227 * Supply a string and an array of disallowed words and any
228 * matched words will be converted to #### or to the replacement
229 * word you've submitted.
230 *
231 * @access public
232 * @param string the text string
233 * @param string the array of censoered words
234 * @param string the optional replacement value
235 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200236 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000237if ( ! function_exists('word_censor'))
238{
239 function word_censor($str, $censored, $replacement = '')
240 {
241 if ( ! is_array($censored))
242 {
243 return $str;
244 }
Barry Mienydd671972010-10-04 16:33:58 +0200245
246 $str = ' '.$str.' ';
Derek Allard2067d1a2008-11-13 22:59:24 +0000247
Derek Jonesf1b721a2009-01-21 17:52:13 +0000248 // \w, \b and a few others do not match on a unicode character
249 // set for performance reasons. As a result words like über
250 // will not match on a word boundary. Instead, we'll assume that
Derek Jonesdaf9c012010-03-05 10:29:30 -0600251 // a bad word will be bookeneded by any of these characters.
Derek Jonesf1b721a2009-01-21 17:52:13 +0000252 $delim = '[-_\'\"`(){}<>\[\]|!?@#%&,.:;^~*+=\/ 0-9\n\r\t]';
253
Derek Allard2067d1a2008-11-13 22:59:24 +0000254 foreach ($censored as $badword)
255 {
256 if ($replacement != '')
257 {
Derek Jonesf1b721a2009-01-21 17:52:13 +0000258 $str = preg_replace("/({$delim})(".str_replace('\*', '\w*?', preg_quote($badword, '/')).")({$delim})/i", "\\1{$replacement}\\3", $str);
Derek Allard2067d1a2008-11-13 22:59:24 +0000259 }
260 else
261 {
Derek Jonesf1b721a2009-01-21 17:52:13 +0000262 $str = preg_replace("/({$delim})(".str_replace('\*', '\w*?', preg_quote($badword, '/')).")({$delim})/ie", "'\\1'.str_repeat('#', strlen('\\2')).'\\3'", $str);
Derek Allard2067d1a2008-11-13 22:59:24 +0000263 }
264 }
Derek Jonesf1b721a2009-01-21 17:52:13 +0000265
Barry Mienydd671972010-10-04 16:33:58 +0200266 return trim($str);
Derek Allard2067d1a2008-11-13 22:59:24 +0000267 }
268}
Barry Mienydd671972010-10-04 16:33:58 +0200269
Derek Allard2067d1a2008-11-13 22:59:24 +0000270// ------------------------------------------------------------------------
271
272/**
273 * Code Highlighter
274 *
275 * Colorizes code strings
276 *
277 * @access public
278 * @param string the text string
279 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200280 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000281if ( ! function_exists('highlight_code'))
282{
283 function highlight_code($str)
Barry Mienydd671972010-10-04 16:33:58 +0200284 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000285 // The highlight string function encodes and highlights
286 // brackets so we need them to start raw
287 $str = str_replace(array('&lt;', '&gt;'), array('<', '>'), $str);
Barry Mienydd671972010-10-04 16:33:58 +0200288
Derek Allard2067d1a2008-11-13 22:59:24 +0000289 // Replace any existing PHP tags to temporary markers so they don't accidentally
290 // break the string out of PHP, and thus, thwart the highlighting.
Barry Mienydd671972010-10-04 16:33:58 +0200291
292 $str = str_replace(array('<?', '?>', '<%', '%>', '\\', '</script>'),
Derek Allard2067d1a2008-11-13 22:59:24 +0000293 array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'), $str);
294
295 // The highlight_string function requires that the text be surrounded
296 // by PHP tags, which we will remove later
297 $str = '<?php '.$str.' ?>'; // <?
298
Barry Mienydd671972010-10-04 16:33:58 +0200299 // All the magic happens here, baby!
Derek Allard2067d1a2008-11-13 22:59:24 +0000300 $str = highlight_string($str, TRUE);
301
302 // Prior to PHP 5, the highligh function used icky <font> tags
303 // so we'll replace them with <span> tags.
304
305 if (abs(PHP_VERSION) < 5)
306 {
307 $str = str_replace(array('<font ', '</font>'), array('<span ', '</span>'), $str);
308 $str = preg_replace('#color="(.*?)"#', 'style="color: \\1"', $str);
309 }
Barry Mienydd671972010-10-04 16:33:58 +0200310
Derek Allard2067d1a2008-11-13 22:59:24 +0000311 // Remove our artificially added PHP, and the syntax highlighting that came with it
312 $str = preg_replace('/<span style="color: #([A-Z0-9]+)">&lt;\?php(&nbsp;| )/i', '<span style="color: #$1">', $str);
313 $str = preg_replace('/(<span style="color: #[A-Z0-9]+">.*?)\?&gt;<\/span>\n<\/span>\n<\/code>/is', "$1</span>\n</span>\n</code>", $str);
314 $str = preg_replace('/<span style="color: #[A-Z0-9]+"\><\/span>/i', '', $str);
Barry Mienydd671972010-10-04 16:33:58 +0200315
Derek Allard2067d1a2008-11-13 22:59:24 +0000316 // Replace our markers back to PHP tags.
317 $str = str_replace(array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'),
318 array('&lt;?', '?&gt;', '&lt;%', '%&gt;', '\\', '&lt;/script&gt;'), $str);
Barry Mienydd671972010-10-04 16:33:58 +0200319
Derek Allard2067d1a2008-11-13 22:59:24 +0000320 return $str;
321 }
322}
Barry Mienydd671972010-10-04 16:33:58 +0200323
Derek Allard2067d1a2008-11-13 22:59:24 +0000324// ------------------------------------------------------------------------
325
326/**
327 * Phrase Highlighter
328 *
329 * Highlights a phrase within a text string
330 *
331 * @access public
332 * @param string the text string
333 * @param string the phrase you'd like to highlight
334 * @param string the openging tag to precede the phrase with
335 * @param string the closing tag to end the phrase with
336 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200337 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000338if ( ! function_exists('highlight_phrase'))
339{
340 function highlight_phrase($str, $phrase, $tag_open = '<strong>', $tag_close = '</strong>')
341 {
342 if ($str == '')
343 {
344 return '';
345 }
Barry Mienydd671972010-10-04 16:33:58 +0200346
Derek Allard2067d1a2008-11-13 22:59:24 +0000347 if ($phrase != '')
348 {
349 return preg_replace('/('.preg_quote($phrase, '/').')/i', $tag_open."\\1".$tag_close, $str);
350 }
351
352 return $str;
353 }
354}
Derek Jonesdaf9c012010-03-05 10:29:30 -0600355
356// ------------------------------------------------------------------------
357
358/**
359 * Convert Accented Foreign Characters to ASCII
360 *
361 * @access public
362 * @param string the text string
363 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200364 */
Derek Jonesdaf9c012010-03-05 10:29:30 -0600365if ( ! function_exists('convert_accented_characters'))
366{
Eric Barnes5e044802011-01-11 16:10:26 -0500367 function convert_accented_characters($str)
Derek Jonesdaf9c012010-03-05 10:29:30 -0600368 {
369 if ( ! file_exists(APPPATH.'config/foreign_chars'.EXT))
370 {
Eric Barnes5e044802011-01-11 16:10:26 -0500371 return $str;
Derek Jonesdaf9c012010-03-05 10:29:30 -0600372 }
Barry Mienydd671972010-10-04 16:33:58 +0200373
Derek Jonesdaf9c012010-03-05 10:29:30 -0600374 include APPPATH.'config/foreign_chars'.EXT;
Barry Mienydd671972010-10-04 16:33:58 +0200375
Derek Jonesdaf9c012010-03-05 10:29:30 -0600376 if ( ! isset($foreign_characters))
377 {
Eric Barnes5e044802011-01-11 16:10:26 -0500378 return $str;
Derek Jonesdaf9c012010-03-05 10:29:30 -0600379 }
Barry Mienydd671972010-10-04 16:33:58 +0200380
Eric Barnes5e044802011-01-11 16:10:26 -0500381 return preg_replace(array_keys($foreign_characters), array_values($foreign_characters), $str);
Derek Jonesdaf9c012010-03-05 10:29:30 -0600382 }
383}
Barry Mienydd671972010-10-04 16:33:58 +0200384
Derek Allard2067d1a2008-11-13 22:59:24 +0000385// ------------------------------------------------------------------------
386
387/**
388 * Word Wrap
389 *
390 * Wraps text at the specified character. Maintains the integrity of words.
391 * Anything placed between {unwrap}{/unwrap} will not be word wrapped, nor
392 * will URLs.
393 *
394 * @access public
395 * @param string the text string
396 * @param integer the number of characters to wrap at
397 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200398 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000399if ( ! function_exists('word_wrap'))
400{
401 function word_wrap($str, $charlim = '76')
402 {
403 // Se the character limit
404 if ( ! is_numeric($charlim))
405 $charlim = 76;
Barry Mienydd671972010-10-04 16:33:58 +0200406
Derek Allard2067d1a2008-11-13 22:59:24 +0000407 // Reduce multiple spaces
408 $str = preg_replace("| +|", " ", $str);
Barry Mienydd671972010-10-04 16:33:58 +0200409
Derek Allard2067d1a2008-11-13 22:59:24 +0000410 // Standardize newlines
411 if (strpos($str, "\r") !== FALSE)
412 {
Barry Mienydd671972010-10-04 16:33:58 +0200413 $str = str_replace(array("\r\n", "\r"), "\n", $str);
Derek Allard2067d1a2008-11-13 22:59:24 +0000414 }
Barry Mienydd671972010-10-04 16:33:58 +0200415
416 // If the current word is surrounded by {unwrap} tags we'll
Derek Allard2067d1a2008-11-13 22:59:24 +0000417 // strip the entire chunk and replace it with a marker.
418 $unwrap = array();
419 if (preg_match_all("|(\{unwrap\}.+?\{/unwrap\})|s", $str, $matches))
420 {
421 for ($i = 0; $i < count($matches['0']); $i++)
422 {
Barry Mienydd671972010-10-04 16:33:58 +0200423 $unwrap[] = $matches['1'][$i];
Derek Allard2067d1a2008-11-13 22:59:24 +0000424 $str = str_replace($matches['1'][$i], "{{unwrapped".$i."}}", $str);
425 }
426 }
Barry Mienydd671972010-10-04 16:33:58 +0200427
428 // Use PHP's native function to do the initial wordwrap.
429 // We set the cut flag to FALSE so that any individual words that are
Derek Allard2067d1a2008-11-13 22:59:24 +0000430 // too long get left alone. In the next step we'll deal with them.
431 $str = wordwrap($str, $charlim, "\n", FALSE);
Barry Mienydd671972010-10-04 16:33:58 +0200432
Derek Allard2067d1a2008-11-13 22:59:24 +0000433 // Split the string into individual lines of text and cycle through them
434 $output = "";
Barry Mienydd671972010-10-04 16:33:58 +0200435 foreach (explode("\n", $str) as $line)
Derek Allard2067d1a2008-11-13 22:59:24 +0000436 {
437 // Is the line within the allowed character count?
438 // If so we'll join it to the output and continue
439 if (strlen($line) <= $charlim)
440 {
Barry Mienydd671972010-10-04 16:33:58 +0200441 $output .= $line."\n";
Derek Allard2067d1a2008-11-13 22:59:24 +0000442 continue;
443 }
Barry Mienydd671972010-10-04 16:33:58 +0200444
Derek Allard2067d1a2008-11-13 22:59:24 +0000445 $temp = '';
Barry Mienydd671972010-10-04 16:33:58 +0200446 while((strlen($line)) > $charlim)
Derek Allard2067d1a2008-11-13 22:59:24 +0000447 {
448 // If the over-length word is a URL we won't wrap it
449 if (preg_match("!\[url.+\]|://|wwww.!", $line))
450 {
451 break;
452 }
453
454 // Trim the word down
455 $temp .= substr($line, 0, $charlim-1);
456 $line = substr($line, $charlim-1);
457 }
Barry Mienydd671972010-10-04 16:33:58 +0200458
459 // If $temp contains data it means we had to split up an over-length
Derek Allard2067d1a2008-11-13 22:59:24 +0000460 // word into smaller chunks so we'll add it back to our current line
461 if ($temp != '')
462 {
Barry Mienydd671972010-10-04 16:33:58 +0200463 $output .= $temp."\n".$line;
Derek Allard2067d1a2008-11-13 22:59:24 +0000464 }
465 else
466 {
467 $output .= $line;
468 }
469
470 $output .= "\n";
471 }
472
473 // Put our markers back
474 if (count($unwrap) > 0)
Barry Mienydd671972010-10-04 16:33:58 +0200475 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000476 foreach ($unwrap as $key => $val)
477 {
478 $output = str_replace("{{unwrapped".$key."}}", $val, $output);
479 }
480 }
481
482 // Remove the unwrap tags
483 $output = str_replace(array('{unwrap}', '{/unwrap}'), '', $output);
484
Barry Mienydd671972010-10-04 16:33:58 +0200485 return $output;
Derek Allard2067d1a2008-11-13 22:59:24 +0000486 }
487}
Barry Mienydd671972010-10-04 16:33:58 +0200488
Greg Akercbe32472010-08-05 14:09:20 -0500489// ------------------------------------------------------------------------
490
Greg Aker0f6b7c12010-08-05 14:11:14 -0500491/**
492 * Ellipsize String
493 *
494 * This function will strip tags from a string, split it at its max_length and ellipsize
495 *
Barry Mienydd671972010-10-04 16:33:58 +0200496 * @param string string to ellipsize
Greg Aker0f6b7c12010-08-05 14:11:14 -0500497 * @param integer max length of string
498 * @param mixed int (1|0) or float, .5, .2, etc for position to split
Barry Mienydd671972010-10-04 16:33:58 +0200499 * @param string ellipsis ; Default '...'
Greg Aker0f6b7c12010-08-05 14:11:14 -0500500 * @return string ellipsized string
501 */
Greg Akercbe32472010-08-05 14:09:20 -0500502if ( ! function_exists('ellipsize'))
503{
Greg Akercbe32472010-08-05 14:09:20 -0500504 function ellipsize($str, $max_length, $position = 1, $ellipsis = '&hellip;')
505 {
506 // Strip tags
507 $str = trim(strip_tags($str));
508
509 // Is the string long enough to ellipsize?
510 if (strlen($str) <= $max_length)
511 {
512 return $str;
513 }
514
515 $beg = substr($str, 0, floor($max_length * $position));
516
517 $position = ($position > 1) ? 1 : $position;
518
519 if ($position === 1)
520 {
521 $end = substr($str, 0, -($max_length - strlen($beg)));
522 }
523 else
524 {
525 $end = substr($str, -($max_length - strlen($beg)));
526 }
527
Barry Mienydd671972010-10-04 16:33:58 +0200528 return $beg.$ellipsis.$end;
Greg Akercbe32472010-08-05 14:09:20 -0500529 }
530}
Derek Allard2067d1a2008-11-13 22:59:24 +0000531
532/* End of file text_helper.php */
Derek Jonesa3ffbbb2008-05-11 18:18:29 +0000533/* Location: ./system/helpers/text_helper.php */