Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Funkcja usuwająca znaki niealfanumeryczne
-Mesajah-
post
Post #1





Goście







Witam,

Czy jest jakaś funkcja, która pozwala usuwać wszystkie znaki niealfanumeryczne ze stringa (w celu stworzenia przyjaznego linka) ?

Np chciałbym zamienić:
  1. $a='Adam Mickiewicz - Dziady (1820)!'^&*_';

na:
  1. $b='adam-mickiewicz-dziady-1820';


Jak najprościej osiągnąć taki efekt ?

Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
-mesajah-
post
Post #2





Goście







Dzięki, część już jest ok, ale znalazłem jeszcze coś takiego:

  1. class hUrls
  2. {
  3. private $a = array( 'Ę', 'Ó', 'Ą', 'Ś', 'Ł', 'Ż', 'Ź', 'Ć', 'Ń', 'ę', 'ó', 'ą',
  4. 'ś', 'ł', 'ż', 'ź', 'ć', 'ń' );
  5. private $b = array( 'E', 'O', 'A', 'S', 'L', 'Z', 'Z', 'C', 'N', 'e', 'o', 'a',
  6. 's', 'l', 'z', 'z', 'c', 'n' );
  7.  
  8. public function Parse( $string )
  9. {
  10. $string = str_replace( $this -> a, $this -> b, $string );
  11. $string = preg_replace( '#[^a-z0-9]#is', ' ', $string );
  12. $string = trim( $string );
  13. $string = preg_replace( '#\s{2,}#', ' ', $string );
  14. $string = str_replace( ' ', '-', $string );
  15. return $string;
  16. }
  17. }


Gdy próbuję wywołać tą funkcję:
  1. $string="śćą#$$$ --śćóżź";
  2. echo Parse($string);


Dostaje info:
Call to undefined function Parse()

Dlaczego ?
Go to the top of the page
+Quote Post

Posty w temacie


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: 26.12.2025 - 20:22