Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [php] wyświetlenie x znaków
GreenGo
post 10.03.2006, 18:02:05
Post #1





Grupa: Zarejestrowani
Postów: 265
Pomógł: 4
Dołączył: 30.08.2004

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


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.
Go to the top of the page
+Quote Post
Balas
post 10.03.2006, 18:06:25
Post #2





Grupa: Zarejestrowani
Postów: 347
Pomógł: 0
Dołączył: 27.08.2005
Skąd: Inowrocław

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


http://pl.php.net/manual/pl/function.substr.php

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

4 min tongue.gif


Ten post edytował OnE.Killer 10.03.2006, 18:13:30


--------------------
Go to the top of the page
+Quote Post
mike
post 10.03.2006, 18:10:01
Post #3





Grupa: Przyjaciele php.pl
Postów: 7 494
Pomógł: 302
Dołączył: 31.03.2004

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


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
Go to the top of the page
+Quote Post
GreenGo
post 10.03.2006, 18:33:11
Post #4





Grupa: Zarejestrowani
Postów: 265
Pomógł: 4
Dołączył: 30.08.2004

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


Ok dzięki panowie smile.gif działa smile.gif
Go to the top of the page
+Quote Post

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: 20.07.2025 - 08:42