Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Jak usunac wszystko po myslniku
JamalBIG
post
Post #1





Grupa: Zarejestrowani
Postów: 496
Pomógł: 1
Dołączył: 16.01.2008
Skąd: Świnoujście

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


Witam

W jaki sposob usunac wszystko co mam po drugim myslniku np. "Jakas Nazwa - Czegos - Cos Tam" do postaci "Jakas Nazwa - Czegos"

Pozdrawiam
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
dr_bonzo
post
Post #2





Grupa: Przyjaciele php.pl
Postów: 5 724
Pomógł: 259
Dołączył: 13.04.2004
Skąd: N/A

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


Masz:
  1. <pre><?php
  2. $strings = array( 
  3. "Jakas Nazwa - Czegos - Cos Tam - Lorem - ipsum - i co ty na to?",
  4. "Jakas Nazwa - Czegos - Cos Tam",
  5. "Jakas Nazwa - Czegos",
  6. "Jakas Nazwa",
  7. );
  8. foreach ( $strings as $str )
  9. {
  10. print( '[' . strip_that( $str ) . "]<Br />" );
  11. }
  12.  
  13. function strip_that( $str )
  14. {
  15. $first = strpos( $str, '-' );
  16. if ( $first === FALSE )
  17. {
  18. return $str;
  19. }
  20. $second = strpos( $str, '-', $first + 1 );
  21. if ( $second === FALSE )
  22. {
  23. return $str;
  24. }
  25. return substr( $str, 0, $second );
  26. }
  27. ?>
Go to the top of the page
+Quote Post
pyro
post
Post #3





Grupa: Zarejestrowani
Postów: 2 148
Pomógł: 230
Dołączył: 26.03.2008

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


Cytat(dr_bonzo @ 1.07.2008, 21:19:43 ) *
Masz:
  1. <?php
  2. $strings = array( 
  3. &#092;"Jakas Nazwa - Czegos - Cos Tam - Lorem - ipsum - i co ty na to?\",
  4. &#092;"Jakas Nazwa - Czegos - Cos Tam\",
  5. &#092;"Jakas Nazwa - Czegos\",
  6. &#092;"Jakas Nazwa\",
  7. );
  8. foreach ( $strings as $str )
  9. {
  10. print( '[' . strip_that( $str ) . &#092;"]
  11. &#092;" );
  12. }
  13.  
  14. function strip_that( $str )
  15. {
  16. $first = strpos( $str, '-' );
  17. if ( $first === FALSE )
  18. {
  19. return $str;
  20. }
  21. $second = strpos( $str, '-', $first + 1 );
  22. if ( $second === FALSE )
  23. {
  24. return $str;
  25. }
  26. return substr( $str, 0, $second );
  27. }
  28. ?>


  1. </br ><?php
  2. $a = explode(' - ', $txt);
  3. $str = $a[0].' - '.$a[1];
  4. ?>


nie prościej?



</br >
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: 3.10.2025 - 05:12