Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Usuwanie znaków specjalnych, drobna modyfikacja funkcji
Lirdoner
post
Post #1





Grupa: Zarejestrowani
Postów: 500
Pomógł: 1
Dołączył: 29.09.2009

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


Witam, posiadam taką funkcję która zamienia mi wszystkie znaki specjalne, usuwa spacje, robi male litery tylko chciałbym dopuścić kropkę. Kropki ma nieruszać
  1. function slugify($text)
  2. {
  3. // replace non letter or digits by -
  4. $text = preg_replace('#[^\\pL\d]+#u', '-', $text);
  5.  
  6. // trim
  7. $text = trim($text, '-');
  8.  
  9. // transliterate
  10. if (function_exists('iconv')) {
  11. $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
  12. }
  13.  
  14. // lowercase
  15. $text = strtolower($text);
  16.  
  17. // remove unwanted characters
  18. $text = preg_replace('#[^-\w]+#', '', $text);
  19.  
  20. return $text;
  21. }

Jak to zrobić?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 1)
Michael2318
post
Post #2





Grupa: Zarejestrowani
Postów: 651
Pomógł: 116
Dołączył: 3.06.2012
Skąd: Lędziny

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


  1. function slugify($text)
  2. {
  3. // replace non letter or digits by -
  4. $text = preg_replace('#[^\.\\pL\d]+#u', '-', $text);
  5.  
  6. // trim
  7. $text = trim($text, '-');
  8.  
  9. // transliterate
  10. if (function_exists('iconv')) {
  11. $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
  12. }
  13.  
  14. // lowercase
  15. $text = strtolower($text);
  16.  
  17. // remove unwanted characters
  18. $text = preg_replace('#[^\.\-\w]+#', '', $text);
  19.  
  20. return $text;
  21. }
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 Aktualny czas: 21.08.2025 - 00:31