Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP] Usuwanie znaków specjalnych i wybranych liter
d0m1n1k_
post
Post #1





Grupa: Zarejestrowani
Postów: 208
Pomógł: 3
Dołączył: 13.07.2009
Skąd: Tarnów

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


Witam,
zastanawiam się jak uprościć usuwanie znaków specjalnych i części liter.
Do tej pory używam bardzo łopatologicznej metody:

  1. $tresc_intake = str_replace(" ", "", $tabelka2[1]);
  2. $tresc_intake = str_replace(" ", "", $tresc_intake);
  3. $tresc_intake = str_replace(" ", "", $tresc_intake);
  4. $tresc_intake = str_replace(" ", "", $tresc_intake);
  5. $tresc_intake = str_replace("XXXXXXXXX", "", $tresc_intake);
  6. $tresc_intake = str_replace("0000000000", "", $tresc_intake);
  7. $tresc_intake = str_replace("-", "", $tresc_intake);
  8. $tresc_intake = str_replace("/", "", $tresc_intake);
  9. $tresc_intake = str_replace("*", "", $tresc_intake);
  10. $tresc_intake = str_replace(",", "", $tresc_intake);
  11. $tresc_intake = str_replace(".", "", $tresc_intake);
  12. $tresc_intake = str_replace("_", "", $tresc_intake);
  13. $tresc_intake = str_replace("!", "", $tresc_intake);
  14. $tresc_intake = str_replace("Q", "", $tresc_intake);
  15. $tresc_intake = str_replace("q", "", $tresc_intake);
  16. $tresc_intake = str_replace("I", "", $tresc_intake);
  17. $tresc_intake = str_replace("i", "", $tresc_intake);


Czy jest możliwość ustalenia tego w ramach tablicy lub innego sposobu?
Poza tym jak mogę uniknąć głupich wpisów typu "11111111111111111" czy "XXXXXXXXX"?
Z góry dziękuję za pomoc.

Ten post edytował d0m1n1k_ 31.10.2015, 13:01:41
Go to the top of the page
+Quote Post
markuz
post
Post #2





Grupa: Zarejestrowani
Postów: 1 240
Pomógł: 278
Dołączył: 11.03.2008

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


  1. $string = preg_replace('/( | | |XXXXXXXXX|0000000000|\-|\/|\*|,|\.|_|!|Q|q|I|i)/', '', $string)

Nie unikniesz głupich wpisów - jedyny sposób to moderacja.

Ten post edytował markuz 31.10.2015, 13:07:16
Go to the top of the page
+Quote Post
viking
post
Post #3





Grupa: Zarejestrowani
Postów: 6 381
Pomógł: 1116
Dołączył: 30.08.2006

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


Możesz też str_replace poprawić

  1. $string = 'kjsahd - ksj / sjkldl*ksjdh ';
  2.  
  3. $replace = [' ', '-', '/', '*', ' '];
  4. echo str_replace($replace, '', $string);


Zobacz też trim().
Go to the top of the page
+Quote Post
Pyton_000
post
Post #4





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

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


A co ma być wynikiem?
Go to the top of the page
+Quote Post
d0m1n1k_
post
Post #5





Grupa: Zarejestrowani
Postów: 208
Pomógł: 3
Dołączył: 13.07.2009
Skąd: Tarnów

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


Pokrótce - numer VIN. ale w drodze pobierania przez parsera Simple HTML DOM.
Serwisy z których korzystam wywalają mnóstwo śmieciowych danych które utrudniają bezstresowe zebranie numerów, ale nie jest to niemożliwe ;-)
Go to the top of the page
+Quote Post
Pyton_000
post
Post #6





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

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


preg_replace('/[^A-HJ-NPR-Z0-9]/i, '', $string);

To Ci da dozwolone znaki, teraz musisz sprawdzić długość i poprawność.
Go to the top of the page
+Quote Post

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: 6.10.2025 - 04:42