Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] Ustawienie Modrewrite - usunięcie spacji i polskich znaków
-krzysiuus-
post
Post #1





Goście







Panowie chcę usunąć spacje i polskie znaki z adresów.

Funkcja odpowiedzialna za adresy:

  1. public function get_blog_url($query=FALSE)
  2. {
  3. global $SITEURL, $PRETTYURLS;
  4. $blogurl = $this->getSettingsData("blogurl");
  5. $data = getXML(GSDATAPAGESPATH . $blogurl . '.xml');
  6. $url = find_url($blogurl, $data->parent);
  7.  
  8. if($query)
  9. {
  10. if($query == 'rss')
  11. {
  12. $url = $SITEURL.'plugins/blog/rss.php';
  13. }
  14. elseif($PRETTYURLS == 1 && $this->getSettingsData("prettyurls") == 'Y')
  15. {
  16. $url .= $query . '/';
  17. }
  18. elseif($blogurl == 'index')
  19. {
  20. $url = $SITEURL . "index.php?$query=";
  21. }
  22. else
  23. {
  24. $url = $SITEURL . "index.php?id=$blogurl&$query=";
  25. }
  26. }
  27. return $url;
  28. }


Niestety nie funkcjonuje poprawnie gdyż adresy są ze spacjami i z polskimi znakami...


Poniżej mam funkcję która działa w innym serwisie:
  1. if (isset($_GET['id'])){
  2. $id = str_replace ('..','',$_GET['id']);
  3. $id = str_replace ('/','',$id);
  4. $id = lowercase($id);
  5. } else {
  6. $id = "index";
  7. }


I ta funkcja działa prawidłowo. Polskie znaki zamieniane są na zwykłe litery bez ogonków a spacje na myślinki.

I teraz pytanie jak dodać do tego pierwszego skryptu dodatki aby linki nie miały polskich znaków a spacje były zamieniane na myśliniki.

W htaccess mam coś takiego:

  1. RewriteEngine on
  2.  
  3. # Usually RewriteBase is just '/', but
  4. # replace it with your subdirectory path
  5. RewriteBase /
  6. RewriteRule ^post/([^/.]+)/?$ index.php?id=index&post=$1 [L]
  7. RewriteRule ^tag/([^/.]+)/?$ index.php?id=index&tag=$1 [L]
  8. RewriteRule ^page/([^/.]+)/?$ index.php?id=index&page=$1 [L]
  9. RewriteRule ^archive/([^/.]+)/?$ index.php?id=index&archive=$1 [L]
  10. RewriteRule ^category/([^/.]+)/?$ index.php?id=index&category=$1 [L]
  11. RewriteCond %{REQUEST_FILENAME} !-f
  12. RewriteCond %{REQUEST_FILENAME} !-d
  13. RewriteRule /?([A-Za-z0-9_-]+)/?$ index.php?id=$1 [QSA,L]


Może ktoś zerknąć i nakierować?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
marian84
post
Post #2





Grupa: Zarejestrowani
Postów: 185
Pomógł: 10
Dołączył: 29.01.2008

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


  1.  
  2. function ClearPolishSigns($text)
  3. {
  4. $ReplacePolishSign = array(
  5. 'ą' => 'a', 'Ą' => 'A', 'ę' => 'e', 'Ę' => 'E',
  6. 'ć' => 'c', 'Ć' => 'C', 'ń' => 'n', 'Ń' => 'N', 'ł' => 'l',
  7. 'Ł' => 'L', 'ś' => 's', 'Ś' => 'S', 'ż' => 'z',
  8. 'Ż' => 'Z', 'ź' => 'z', 'Ź' => 'Z', 'ó' => 'o', 'Ó' => 'o'
  9. );
  10.  
  11. return str_replace(array_keys($ReplacePolishSign), array_values($ReplacePolishSign), $text);
  12. }
  13. function FriendlyTitle($text)
  14. {
  15. $text = ClearPolishSigns($text);
  16. $text = strtolower($text);
  17. $text = str_replace(' ', '-', $text);
  18. $text = preg_replace('/[^0-9a-z\-]+/', '', $text);
  19. $text = preg_replace('/[\-]+/', '-', $text);
  20. $text = trim($text, '-');
  21. return $text;
  22. }
  23.  
  24. echo FriendlyTitle('string który chcesz przerobić');
  25.  
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: 6.10.2025 - 20:10