Changeset 258
- Timestamp:
- May 20, 2007 7:00:12 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Utilities.inc.php
r257 r258 157 157 158 158 foreach ($words as $w) { 159 $search[] = '/\b(' . preg_quote($w) . ')\b/i'; 160 $replace[] = '<span class="' . $class . '">$1</span>'; 161 } 162 163 return preg_replace($search, $replace, $text); 159 if ('' != trim($w)) { 160 $search[] = '/\b(' . preg_quote($w) . ')\b/i'; 161 $replace[] = '<span class="' . $class . '">$1</span>'; 162 } 163 } 164 165 return empty($replace) ? $text : preg_replace($search, $replace, $text); 164 166 } 165 167 … … 247 249 * @since 29 Mar 2006 13:48:49 248 250 */ 249 function truncate($str, $len, $where='middle' )251 function truncate($str, $len, $where='middle', $delim='…') 250 252 { 251 253 if ($len <= 3 || mb_strlen($str) <= 3) { … … 256 258 switch ($where) { 257 259 case 'start' : 258 return preg_replace(array(sprintf('/^.{4,}(.{%s})$/sU', $part1 + $part2), '/\s*\.{3,}\s*/sU'), array( '...$1', '...'), $str);260 return preg_replace(array(sprintf('/^.{4,}(.{%s})$/sU', $part1 + $part2), '/\s*\.{3,}\s*/sU'), array($delim . '$1', $delim), $str); 259 261 break; 260 262 default : 261 263 case 'middle' : 262 return preg_replace(array(sprintf('/^(.{%s}).{4,}(.{%s})$/sU', $part1, $part2), '/\s*\.{3,}\s*/sU'), array('$1 ...$2', '...'), $str);264 return preg_replace(array(sprintf('/^(.{%s}).{4,}(.{%s})$/sU', $part1, $part2), '/\s*\.{3,}\s*/sU'), array('$1' . $delim . '$2', $delim), $str); 263 265 break; 264 266 case 'end' : 265 return preg_replace(array(sprintf('/^(.{%s}).{4,}$/sU', $part1 + $part2), '/\s*\.{3,}\s*/sU'), array('$1 ...', '...'), $str);267 return preg_replace(array(sprintf('/^(.{%s}).{4,}$/sU', $part1 + $part2), '/\s*\.{3,}\s*/sU'), array('$1' . $delim, $delim), $str); 266 268 break; 267 269 } … … 350 352 351 353 /** 352 * Returns stats of a file fromthe include path.354 * Tests the existance of a file anywhere in the include path. 353 355 * 354 356 * @param string $file File in include path. 355 * @param mixded $stat Which statistic to return (or null to return all). 356 * @return mixed Value of requested key from fstat(), or false on error. 357 * @return mixed False if file not found, the path of the file if it is found. 357 358 * @author Quinn Comendant <quinn@strangecode.com> 358 359 * @since 03 Dec 2005 14:23:26 359 360 */ 361 function fileExistsIncludePath($file) 362 { 363 $app =& App::getInstance(); 364 365 foreach (explode(PATH_SEPARATOR, get_include_path()) as $path) { 366 $fullpath = $path . DIRECTORY_SEPARATOR . $file; 367 if (file_exists($fullpath)) { 368 $app->logMsg(sprintf('Found file "%s" at path: %s', $file, $fullpath), LOG_DEBUG, __FILE__, __LINE__); 369 return $fullpath; 370 } else { 371 $app->logMsg(sprintf('File "%s" not found in include_path: %s', $file, get_include_path()), LOG_DEBUG, __FILE__, __LINE__); 372 return false; 373 } 374 } 375 } 376 377 /** 378 * Returns stats of a file from the include path. 379 * 380 * @param string $file File in include path. 381 * @param mixed $stat Which statistic to return (or null to return all). 382 * @return mixed Value of requested key from fstat(), or false on error. 383 * @author Quinn Comendant <quinn@strangecode.com> 384 * @since 03 Dec 2005 14:23:26 385 */ 360 386 function statIncludePath($file, $stat=null) 361 387 { 362 388 // Open file pointer read-only using include path. 363 389 if ($fp = fopen($file, 'r', true)) { 364 // File open d successfully, get stats.390 // File opened successfully, get stats. 365 391 $stats = fstat($fp); 366 392 fclose($fp);
Note: See TracChangeset
for help on using the changeset viewer.