Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php] skroty tekstu
Suchy
post
Post #1





Grupa: Zarejestrowani
Postów: 52
Pomógł: 0
Dołączył: 19.03.2006

Ostrzeżenie: (0%)
-----


Witam. JAk wyświetlić np tylko 180 znaków jakiegoś tekstu? Napisał sam co nieco ale to troszke źle działa, bo dzieli rówżnież wyrazy, a ja bym chciał tak, że wyswietla pełne wyrazy
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
son
post
Post #2





Grupa: Zarejestrowani
Postów: 210
Pomógł: 0
Dołączył: 31.01.2004
Skąd: Kraków

Ostrzeżenie: (0%)
-----


Funkcja zaczerpnięta ze smarty (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
  1. <?php
  2.  
  3. function truncate($string, $length = 80, $etc = '...', $break_words = false, $middle = false)
  4. {
  5. if ($length == 0)
  6. return '';
  7.  
  8. if (strlen($string) > $length) {
  9. $length -= strlen($etc);
  10. if (!$break_words && !$middle) {
  11. $string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length+1));
  12. }
  13. if(!$middle) {
  14. return substr($string, 0, $length).$etc;
  15. } else {
  16. return substr($string, 0, $length/2) . $etc . substr($string, -$length/2);
  17. }
  18. } else {
  19. return $string;
  20. }
  21. }
  22.  
  23. ?>
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 5.10.2025 - 04:26