Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP]Usuwanie znaków specjalnych
Forum PHP.pl > Forum > Przedszkole
Lirdoner
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ć?
Michael2318
  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. }
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.