Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Ucinanie tekstu po 150 znakach
vegeta
post 15.04.2012, 17:23:01
Post #1





Grupa: Zarejestrowani
Postów: 122
Pomógł: 0
Dołączył: 9.11.2008

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


Witam.

Chcę, żeby ucinało mi tekst po 150 znakach, ale nie ucinało wyrazów w połowie. Myślę, że trzeba sprawdzić czy następny znak jest spacją tylko nie wiem jak to zrobić.

Oto kod:

Skrot.php:
  1. <?php
  2. if (substr($rekord[4], 0, 150)<$rekord[4]) // 1
  3. {
  4. $kr = '...'; //
  5. }
  6. else
  7. {
  8. $kr = '';
  9. }
  10. ?>


główny plik:
  1. include ("skrot.php");
  2.  
  3. $naz .='<li><a href="news.php?id='.$rekord[0].'">'.$rekord[4].'</a>
  4.  
  5. <p>'.substr($rekord[4], 0, 150).''.$kr.'</p></li>';
  6. }
  7. echo '<p>'.$naz.'</p>';
Go to the top of the page
+Quote Post
Barcelona
post 15.04.2012, 17:53:24
Post #2





Grupa: Zarejestrowani
Postów: 322
Pomógł: 15
Dołączył: 29.01.2010

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


Poczytaj tutaj http://blog.kamilbrenk.pl/gramatyka-w-html-i-css/
Go to the top of the page
+Quote Post
vegeta
post 15.04.2012, 19:42:19
Post #3





Grupa: Zarejestrowani
Postów: 122
Pomógł: 0
Dołączył: 9.11.2008

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


Nie chodzi mi o przenoszenie wyrazów tylko o ucinanie newsa po przekroczeniu 150 znaków, ale żeby nie ucinało wyrazów
Go to the top of the page
+Quote Post
batman
post 15.04.2012, 19:51:10
Post #4





Grupa: Moderatorzy
Postów: 2 921
Pomógł: 269
Dołączył: 11.08.2005
Skąd: 127.0.0.1




To załatwi sprawę.
  1. $text = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.';
  2. if(strlen($text) > 150) {
  3. $text = substr($text, 0, strpos($text, ' ', 150)) . '...';
  4. }
  5. echo $text;


--------------------
I would love to change the world, but they won't give me the source code.
My software never has bugs. It just develops random features.
Go to the top of the page
+Quote Post
vegeta
post 15.04.2012, 21:12:48
Post #5





Grupa: Zarejestrowani
Postów: 122
Pomógł: 0
Dołączył: 9.11.2008

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


Dzięki 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: 18.04.2024 - 16:18