Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Closed TopicStart new topic
> [PHP] Czy jest taka funkcja ?
fredman
post 29.06.2009, 00:12:29
Post #1





Grupa: Zarejestrowani
Postów: 92
Pomógł: 0
Dołączył: 15.12.2006

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


mam taki string

$string ="ala, ola, franek, 2";

jest taka funkcja, która usuwa ostatni element (elementy rozdziela separator - tu przecinek)? Chciałbym się pozbyć cyfry z końca ( i tego przecinka ostatniego tez najlepiej winksmiley.jpg ) a może jakoś poprzez usuniecie wszystkiego co jest cyfrą ?
Go to the top of the page
+Quote Post
Pr0100
post 29.06.2009, 00:24:40
Post #2





Grupa: Zarejestrowani
Postów: 114
Pomógł: 24
Dołączył: 18.01.2008
Skąd: Warszawa

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


  1. <?php
  2. substr($string, 0, -3)
  3. ?>


o ile ostatnia liczba jest zawsze cyfrą


--------------------
Go to the top of the page
+Quote Post
seth-kk
post 29.06.2009, 00:27:30
Post #3





Grupa: Zarejestrowani
Postów: 444
Pomógł: 79
Dołączył: 26.05.2009

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


lub jesli dowolny ostatni element
  1. <?php
  2. $string = explode(', ', $string);
  3. array_pop($string);
  4. $string = implode(', ', $string);
  5. ?>


--------------------
Go to the top of the page
+Quote Post
Pr0100
post 29.06.2009, 00:36:23
Post #4





Grupa: Zarejestrowani
Postów: 114
Pomógł: 24
Dołączył: 18.01.2008
Skąd: Warszawa

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


@seth-kk: nie lepiej tak?

  1. <?php
  2. substr($string, 0, strrpos($string, ','));
  3. ?>


--------------------
Go to the top of the page
+Quote Post
Ociu
post 29.06.2009, 11:49:18
Post #5





Grupa: Moderatorzy
Postów: 1 566
Pomógł: 37
Dołączył: 14.05.2003
Skąd: Kraków




Zamykam, zacznij korzystać z manuala.
Go to the top of the page
+Quote Post

Closed 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: 2.06.2024 - 10:41