Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] Zmiękczenia w url
-4in1-
post
Post #1





Goście







Witam, czy wie ktoś jak zrobić aby URL zamiast
www.strona.pl/to-jest-mój-artykuł,
wyświetlał:
www.strona.pl/to-jest-moj-artkul ?

Fragment kodu skryptu
  1. function generate_seo_link($input,$replace = '-',$remove_words = true,$words_array = array() )
  2. {
  3. //make it lowercase, remove punctuation, remove multiple/leading/ending spaces
  4. $return = trim(ereg_replace(' +',' ',preg_replace('/[^a-zA-Z0-9\sążśźćęłóńĄŻŚŹĆĘŃÓŁ]/','',strtolower($input))));
  5.  
  6. //remove words, if not helpful to seo
  7. //i like my defaults list in remove_words(), so I wont pass that array
  8. if($remove_words) { $return = remove_words($return,$replace,$words_array); }
  9.  
  10. //convert the spaces to whatever the user wants
  11. //usually a dash or underscore..
  12. //...then return the value.
  13. return str_replace(' ',$replace,$return);
  14. }


Znalazłem podpowiedzi typu http://blog.poradnik-webmastera.com/57/skr...-krzaczki-w-url, jednak nie wiem jak to wprowadzić w ten skrypt...
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 8)
Sephirus
post
Post #2





Grupa: Zarejestrowani
Postów: 1 527
Pomógł: 438
Dołączył: 28.06.2011
Skąd: Warszawa

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


  1. $adres = 'www.strona.pl/to-jest-mój-artykuł';
  2.  
  3. $polskieLiterki = 'ążśźęćńółĄŻŚŹĘĆŃÓŁ';
  4. $odpowiedniki = 'azszecnolAZSZECNOL';
  5.  
  6. $adres = str_replace(str_split($polskieLiterki), str_split($odpowiedniki), $adres);
  7.  
  8. echo $adres; // www.strona.pl/to-jest-moj-artykul
Go to the top of the page
+Quote Post
-4in1-
post
Post #3





Goście







Z z tym www.strona.pl/to-jest-mój-artykuł to byl przyklad (IMG:style_emoticons/default/wink.gif)
chodzi mi o dodanie takiej formulki do skryptu ktory podalem powyzej, aby zamienialo wszystkie adresy.
Go to the top of the page
+Quote Post
Sephirus
post
Post #4





Grupa: Zarejestrowani
Postów: 1 527
Pomógł: 438
Dołączył: 28.06.2011
Skąd: Warszawa

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


Hmm bez urazy ale czy to aż takie trudne wrzucić te parę linijek na początek tej funkcji? (IMG:style_emoticons/default/smile.gif) Tylko z głową oczywiście (IMG:style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post
-Gość-
post
Post #5





Goście







Szczerze, nie potrafie ... ; x
Go to the top of the page
+Quote Post
Sephirus
post
Post #6





Grupa: Zarejestrowani
Postów: 1 527
Pomógł: 438
Dołączył: 28.06.2011
Skąd: Warszawa

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


  1. function generate_seo_link($input,$replace = '-',$remove_words = true,$words_array = array() )
  2. {
  3. // TUTAJ DODAJEMY
  4. $polskieLiterki = 'ążśźęćńółĄŻŚŹĘĆŃÓŁ';
  5. $odpowiedniki = 'azszecnolAZSZECNOL';
  6.  
  7. $input = str_replace(str_split($polskieLiterki), str_split($odpowiedniki), $input);
  8. // I MAŁA POPRAWKA PONIŻEJ
  9.  
  10.  
  11. //make it lowercase, remove punctuation, remove multiple/leading/ending spaces
  12. $return = trim(ereg_replace(' +',' ',preg_replace('/[^a-zA-Z0-9\s]/','',strtolower($input)))); // TU JUŻ USUWANIE POLSKICH LITEREK JEST ZBĘDNE
  13.  
  14. //remove words, if not helpful to seo
  15. //i like my defaults list in remove_words(), so I wont pass that array
  16. if($remove_words) { $return = remove_words($return,$replace,$words_array); }
  17.  
  18. //convert the spaces to whatever the user wants
  19. //usually a dash or underscore..
  20. //...then return the value.
  21. return str_replace(' ',$replace,$return);
  22. }
Go to the top of the page
+Quote Post
-4in1-
post
Post #7





Goście







Powiem tak, cos dziala ale nie tak jak trzeba (IMG:style_emoticons/default/wink.gif) Otoz url wyswietlaja sie tak:

szczęście
www.strona.pl/szczaasccie
telefon komórkowy
www.strona.pl/telefon-komcnrkowy/
zioła
www.strona.pl/ziosla
  1. każda

www.strona.pl/kaszdaz
Go to the top of the page
+Quote Post
Sephirus
post
Post #8





Grupa: Zarejestrowani
Postów: 1 527
Pomógł: 438
Dołączył: 28.06.2011
Skąd: Warszawa

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


Ok masz rację zapomniałem o tym że str_split nie obsługuje znaków podwójno-bajtowych w związku z tym zamień moją wstawkę na:

  1. // TUTAJ DODAJEMY
  2. $polskieLiterki = array('ą','ż','ś','ź','ę','ć','ń','ó','ł','Ą','Ż','Ś','Ź','Ę','Ć','Ń','Ó','Ł');
  3. $odpowiedniki = array('a','z','s','z','e','c','n','o','l','A','Z','S','Z','E','C','N','O','L');
  4.  
  5. $input = str_replace($polskieLiterki, $odpowiedniki, $input);
  6. // I MAŁA POPRAWKA PONIŻEJ


EDIT: pośpiech jest złym doradcą... (IMG:style_emoticons/default/smile.gif)

Ten post edytował Sephirus 19.02.2013, 16:36:20
Go to the top of the page
+Quote Post
-4in1-
post
Post #9





Goście







Działa! Dzięki wielkie kolego, widać, że wiesz co robisz (IMG:style_emoticons/default/smile.gif) Pozdrawiam serdecznie
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: 26.08.2025 - 14:05