Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Jak usunac wszystko po myslniku
JamalBIG
post 1.07.2008, 19:01:23
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
pyro
post 1.07.2008, 19:26:22
Post #2





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

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


sam wpadlem na conajmniej 4 sposoby zaraz po przeczytaniu posta, nastepnym razem pomyśl chwile ;/

  1. <?php
  2. $a = explode(' - ', $txt);
  3. $new = implode(' - ', $a);
  4. ?>


--------------------
ET LINGUA EIUS LOQUETUR IUDICIUM
Go to the top of the page
+Quote Post
dr_bonzo
post 1.07.2008, 19:28:17
Post #3





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

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


a przy 10ciu myslnikach?


--------------------
Nie lubię jednorożców.
Go to the top of the page
+Quote Post
pyro
post 1.07.2008, 19:30:04
Post #4





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

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


Cytat(dr_bonzo @ 1.07.2008, 20:28:17 ) *
a przy 10ciu myslnikach?


dr_bonzo, ja nie bez powodu dałem TAKIE rozwiązanie smile.gif


--------------------
ET LINGUA EIUS LOQUETUR IUDICIUM
Go to the top of the page
+Quote Post
JamalBIG
post 1.07.2008, 20:00:50
Post #5





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

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


Zrobilem taj jak napisales, z moim przykladem z gory dziala ale z tekstem wywolanym z bazy danych nie... Mam taki kod:

  1. <?php
  2. $name_long = str_replace("_", " ", $name_long);
  3. $name_long = str_replace("VA-", "", $name_long);
  4. $name_long = str_replace("-", " - ", $name_long);
  5. $a = explode(' - ', $name_long);
  6. array_pop($a);
  7. $new = implode(' - ', $a);
  8. ?>


Wiecie moze co tu jest nie tak?

Pozdrawiam
Go to the top of the page
+Quote Post
pyro
post 1.07.2008, 20:06:22
Post #6





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

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


a co sie dzieje? co znaczy, że nie działa?


--------------------
ET LINGUA EIUS LOQUETUR IUDICIUM
Go to the top of the page
+Quote Post
dr_bonzo
post 1.07.2008, 20:19:43
Post #7





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. ?>


--------------------
Nie lubię jednorożców.
Go to the top of the page
+Quote Post
pyro
post 1.07.2008, 20:27:22
Post #8





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 >


--------------------
ET LINGUA EIUS LOQUETUR IUDICIUM
Go to the top of the page
+Quote Post
JamalBIG
post 1.07.2008, 20:57:08
Post #9





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

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


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

Dzieki wielkie, wczesniej poprostu nic nie zmienial ten pierwszy kod...
Go to the top of the page
+Quote Post
cbagov
post 1.07.2008, 21:18:28
Post #10





Grupa: Zarejestrowani
Postów: 181
Pomógł: 18
Dołączył: 19.04.2008

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


OR

$str = "Jakas Nazwa - Czegos - Cos Tam";

$str1 = strtok($str, "-")."-".strtok("-");
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: 31.07.2025 - 08:44