Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [php] wyświetlenie x znaków
Forum PHP.pl > Forum > Przedszkole
GreenGo
Witam.
Mam tekst w bazie o dłógości np. 500 znaków.
W jaki sposób moge wyświetlić piewsze 100 znaków tego tekstu ?
Pozdrawiam.
Balas
http://pl.php.net/manual/pl/function.substr.php

edit:
Cytat
---update---
~OnE.Killer był szybciej

4 min tongue.gif
mike
substr()
lub ładniej (rodem ze Smarty'ego):
  1. <?php
  2. /**
  3.  * Purpose: Truncate a string to a certain length if necessary,
  4.  *  optionally splitting in the middle of a word, and
  5.  *  appending the $etc string.
  6.  * @param string
  7.  * @param integer
  8.  * @param string
  9.  * @param boolean
  10.  * @return string
  11.  */
  12. function truncate($string, $length = 80, $etc = '...', $break_words = false)
  13. {
  14. if ($length == 0)
  15. return '';
  16.  
  17. if (strlen($string) > $length) {
  18. $length -= strlen($etc);
  19. if (!$break_words)
  20. $string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length+1));
  21.  
  22. return substr($string, 0, $length).$etc;
  23. } else
  24. return $string;
  25. }
  26.  
  27. ?>


---update---
~OnE.Killer był szybciej smile.gif
GreenGo
Ok dzięki panowie smile.gif działa smile.gif
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.