Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP]Generowanie przyjaznych linków
Forum PHP.pl > Forum > PHP
axwell
Mam taki oto kod, który z tytułu artykuły generuje przyjazny link (zamienia spacje itd)

  1. function seolink($string) {
  2. $from=', . ; ( ) _ \ /';
  3. $array=explode(' ',$from);
  4. $array[]=' ';
  5. $string=str_replace($array, '_', $string);
  6. $string=iconv('utf-8', 'ascii//translit', $string);
  7. $string=preg_replace('#[^a-z0-9\_]#si ', '', $string);
  8. return str_replace('\'', '', $string);
  9. };


Na localhost na moim komputerze jest wszystko ok, przykładowo dla tytułu "KWAŚNY STRÓJ" tworzy mi link
....a23-Kwasny_stroj.html

Natomiast po wrzucenie na serwer, zamiast zaminiac polskie znaki na te "bez ogonkow" skrypt po prostu je wyrzuca całkiem. Przykład:
....a23-Kwany_strj.html
Mephistofeles
Może nie ma iconv? Albo jest źle skonfigurowany?
axwell
Mam dostęp tylko do cPanel-a, czy mogę gdzieś podejrzeć konfiguracje iconv?
AndyPSV
uzyj tej funkcji:

  1. function _url($name) { # parse url
  2. $sign = '-';
  3. $n = str_replace(' ',$sign,$name);
  4. $n = strip_tags($n);
  5. $n = str_replace("/",$sign,$n);
  6. $n = str_replace('\"',$sign,$n);
  7. $n = str_replace('.',$sign,$n);
  8. $n = str_replace(',','',$n);
  9. $n = str_replace('?','',$n);
  10. $n = str_replace('!','',$n);
  11. $n = str_replace('(','',$n);
  12. $n = str_replace(')','',$n);
  13. $n = str_replace(']','',$n);
  14. $n = str_replace('[','',$n);
  15. $n = str_replace(':','',$n);
  16. $n = str_replace('&','',$n);
  17. $n = str_replace('%','',$n);
  18. $n = str_replace('#','',$n);
  19. $n = str_replace('"','',$n);
  20. $n = str_replace('+','',$n);
  21. $n = str_replace(' - ','',$n);
  22. $n = str_replace('--','-',$n);
  23. $n = str_replace('--','-',$n);
  24. $n = str_replace('quot;','',$n);
  25. $n = str_replace('ndash;-','',$n);
  26. $n = str_replace("'m",$sign.'am',$n);
  27. $n = str_replace("'ve",$sign.'have',$n);
  28. $n = str_replace("'s",$sign.'is',$n);
  29. $n = str_replace("'",'',$n);
  30.  
  31. /* PL */
  32. $n = str_replace("Ą",'A',$n);
  33. $n = str_replace("ą",'a',$n);
  34. $n = str_replace("Ć",'C',$n);
  35. $n = str_replace("ć",'c',$n);
  36. $n = str_replace("Ę",'e',$n);
  37. $n = str_replace("ę",'e',$n);
  38. $n = str_replace("Ł",'l',$n);
  39. $n = str_replace("ł",'l',$n);
  40. $n = str_replace("Ń",'n',$n);
  41. $n = str_replace("ń",'n',$n);
  42. $n = str_replace("Ó",'o',$n);
  43. $n = str_replace("ó",'o',$n);
  44. $n = str_replace("Ś",'s',$n);
  45. $n = str_replace("ś",'s',$n);
  46. $n = str_replace("Ź",'z',$n);
  47. $n = str_replace("ź",'z',$n);
  48. $n = str_replace("Ż",'z',$n);
  49. $n = str_replace("ż",'z',$n);
  50.  
  51. if(substr($n,-1) == '.') $n = substr($n,0,strlen($n)-1);
  52. if(substr($n,-1) == $sign) $n = substr($n,0,strlen($n)-1);
  53. if(substr($n,-1) == $sign) $n = substr($n,0,strlen($n)-1);
  54. if(substr($n,-1) == $sign) $n = substr($n,0,strlen($n)-1);
  55.  
  56. return strtolower($n);
  57. }
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.