bethebest
24.05.2008, 11:59:38
mam taka funkcje do zmiany tytulu danego artykulu na PERMALINKA. Czyli jesli jest tytuł "Zo¶ka poszła spać" to zmmienia na zoska-poszla-spac. Problem tkwi w tym, że nie wiem jak zmienić litery ę¶±ć itp na esac itp . $result = preg_replace('/¶/', ' s', $result); nnie działa;/
public function getStrippedTitle()
{
$result = strtolower($this->getTitle());
// strip all non word chars
$result = preg_replace('/\W/', ' ', $result);
// replace all white space sections with a dash
$result = preg_replace('/\ +/', '-', $result);
// trim dashes
$result = preg_replace('/\-$/', '', $result);
$result = preg_replace('/^\-/', '', $result);
return $result;
}
.radex
24.05.2008, 12:09:27
$result = str_replace('ś', 's', $result);
i tak z pozostałymi.
btw. Jaki to ma związek z frameworkami?
bethebest
24.05.2008, 12:15:40
a to akurat z przykladu z tutoriala symfony, nie dziala, w pasku przegladarki wyskakuja krzaczki np %E% itp
.radex
24.05.2008, 12:17:24
działa, tylko Ľle to robisz.
Kod
public function getStrippedTitle()
{
$result = strtolower($this->getTitle());
// strip all non word chars
$result = preg_replace('/\W/', ' ', $result);
// replace all white space sections with a dash
$result = preg_replace('/\ +/', '-', $result);
// trim dashes
$result = preg_replace('/\-$/', '', $result);
$result = preg_replace('/^\-/', '', $result);
$result = str_replace('¶', 's', $result);
$result = str_replace('ę', 'e', $result);
$result = str_replace('±', 'a', $result);
// tutaj pozostałe pozamieniaj.
return $result;
}
bethebest
24.05.2008, 12:31:37
dziala ale jesli ta funkcje co zamienia znak np ś na dam na sam poczatek wtedy zamieni tylko ś, czyli
$result = str_replace('ś', 's', $result);
$result = str_replace('ę', 'e', $result);
to z wyrazu święty, zamieni tylko ś a ę bedzie krzeczkowate...
znalazlem rozwiazanie:
$polskie = array('ą','ć','ę','ł','ń','ó','ś','ź','ż','Ą','Ć','Ę','Ł','Ń','Ó','Ś','Ź','Ż');
$zmienione = array('a','c','e','l','n','o','s','z','z','A','C','E','L','N','O','S','Z','Z');
$result = str_replace($polskie, $zmienione, $result);
tak zadziala prawidlowo pozdrawiam:)