Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] funkcja
mathevs
post 3.01.2013, 15:37:20
Post #1





Grupa: Zarejestrowani
Postów: 39
Pomógł: 0
Dołączył: 5.11.2012

Ostrzeżenie: (10%)
X----


  1. function limit_chars($str, $limit = 100, $end_char = NULL, $preserve_words = FALSE)
  2.  
  3. {
  4.  
  5. $end_char = ($end_char === NULL) ? '?' : $end_char;
  6.  
  7.  
  8.  
  9. $limit = (int) $limit;
  10.  
  11.  
  12.  
  13. if (trim($str) === '' OR strlen($str) <= $limit)
  14.  
  15. return $str;
  16.  
  17.  
  18.  
  19. if ($limit <= 0)
  20.  
  21. return $end_char;
  22.  
  23.  
  24.  
  25. if ($preserve_words === FALSE)
  26.  
  27. return rtrim(substr($str, 0, $limit)).$end_char;
  28.  
  29.  
  30.  
  31. // Don't preserve words. The limit is considered the top limit.
  32.  
  33. // No strings with a length longer than $limit should be returned.
  34.  
  35. if ( ! preg_match('/^.{0,'.$limit.'}\s/us', $str, $matches))
  36.  
  37. return $end_char;
  38.  
  39.  
  40.  
  41. return rtrim($matches[0]).((strlen($matches[0]) === strlen($str)) ? '' : $end_char);
  42.  
  43. }


teraz niech ktoś mi powie jak to podlączyć ... próbowałem ale coś mi nie wychodzi haha.gif

z góry dzięki tongue.gif

Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 14.08.2025 - 02:15