/* Funkcja do usuwania polskich znakow z tekstu o dowolnym kodowaniu Autor: Marius Ma\ximus Inspiracja: http://4programmers.net/PHP/FAQ/Jak_zmieni%C4%87_kodowanie_tekstu_nie_maj%C4%85c_dost%C4%99pu_do_funkcji_iconv_%5C Sposob uzycia: $zmienna = _no_pl("jakiś tekst z PL-znakami np. ŻÓŁĆ"); */ function _no_pl($tekst) { $tabela = Array( //WIN "\xb9" => "a", "\xa5" => "A", "\xe6" => "c", "\xc6" => "C", "\xea" => "e", "\xca" => "E", "\xb3" => "l", "\xa3" => "L", "\xf3" => "o", "\xd3" => "O", "\x9c" => "s", "\x8c" => "S", "\x9f" => "z", "\xaf" => "Z", "\xbf" => "z", "\xac" => "Z", "\xf1" => "n", "\xd1" => "N", //UTF "\xc4\x85" => "a", "\xc4\x84" => "A", "\xc4\x87" => "c", "\xc4\x86" => "C", "\xc4\x99" => "e", "\xc4\x98" => "E", "\xc5\x82" => "l", "\xc5\x81" => "L", "\xc3\xb3" => "o", "\xc3\x93" => "O", "\xc5\x9b" => "s", "\xc5\x9a" => "S", "\xc5\xbc" => "z", "\xc5\xbb" => "Z", "\xc5\xba" => "z", "\xc5\xb9" => "Z", "\xc5\x84" => "n", "\xc5\x83" => "N", //ISO "\xb1" => "a", "\xa1" => "A", "\xe6" => "c", "\xc6" => "C", "\xea" => "e", "\xca" => "E", "\xb3" => "l", "\xa3" => "L", "\xf3" => "o", "\xd3" => "O", "\xb6" => "s", "\xa6" => "S", "\xbc" => "z", "\xac" => "Z", "\xbf" => "z", "\xaf" => "Z", "\xf1" => "n", "\xd1" => "N"); //$tekst = preg_replace( '#[^a-z0-9]#is', ' ', $tekst ); //$tekst = trim( $tekst ); //$tekst = preg_replace( '#\s{2,}#', ' ', $tekst ); $tekst = str_replace( ' ', '-', $tekst ); $tekst = str_replace( '–', '-', $tekst ); $tekst = str_replace( ',', '-', $tekst ); $tekst = str_replace( '.', '-', $tekst ); $tekst = str_replace( '--', '-', $tekst ); $tekst = str_replace( '---', '-', $tekst ); $tekst = str_replace( ';', '', $tekst ); $tekst = str_replace( '/', '', $tekst ); $tekst = str_replace( '"', '', $tekst ); $tekst = str_replace( "'", '', $tekst ); $tekst = str_replace( '~', '', $tekst ); $tekst = str_replace( '|', '', $tekst ); $tekst = str_replace( ':', '', $tekst ); $tekst = str_replace( ';', '', $tekst ); $tekst = str_replace( '&', '', $tekst ); $tekst = str_replace( '%', '', $tekst ); $tekst = str_replace( '$', '', $tekst ); $tekst = str_replace( '(', '', $tekst ); $tekst = str_replace( ')', '', $tekst ); $tekst = str_replace( '[', '', $tekst ); $tekst = str_replace( ']', '', $tekst ); $tekst = str_replace( '{', '', $tekst ); $tekst = str_replace( '}', '', $tekst ); $tekst = str_replace( '!', '', $tekst ); $tekst = str_replace( '?', '', $tekst ); $tekst = str_replace( '+', '', $tekst ); $tekst = str_replace( '#', '', $tekst ); $tekst = str_replace( 'Ś', 's', $tekst ); $tekst = str_replace( 'Ż', 'z', $tekst ); $tekst = str_replace( 'Ą', 'a', $tekst ); $tekst = str_replace( 'Ć', 'c', $tekst ); $tekst = str_replace( 'ą', 'a', $tekst ); $tekst = str_replace( 'ć', 'c', $tekst ); $tekst = str_replace( 'Ż', 'z', $tekst ); $tekst = str_replace( 'ż', 'z', $tekst ); $tekst = str_replace( 'Ł', 'l', $tekst ); $tekst = str_replace( 'ł', 'l', $tekst ); $tekst = str_replace( 'Ó', 'o', $tekst ); $tekst = str_replace( 'ó', 'o', $tekst ); $tekst = str_replace( 'Ń', 'n', $tekst ); $tekst = str_replace( 'ń', 'n', $tekst ); $tekst = str_replace( 'Ę', 'e', $tekst ); $tekst = str_replace( 'ę', 'e', $tekst ); $tekst = str_replace( '--', '-', $tekst ); $tekst = strtolower($tekst); $tekst = strtr($tekst,$tabela); $tekst = urlencode($tekst); return $tekst; } function tolink($tekst) { $tabela = Array( //WIN "\xb9" => "a", "\xa5" => "A", "\xe6" => "c", "\xc6" => "C", "\xea" => "e", "\xca" => "E", "\xb3" => "l", "\xa3" => "L", "\xf3" => "o", "\xd3" => "O", "\x9c" => "s", "\x8c" => "S", "\x9f" => "z", "\xaf" => "Z", "\xbf" => "z", "\xac" => "Z", "\xf1" => "n", "\xd1" => "N", //UTF "\xc4\x85" => "a", "\xc4\x84" => "A", "\xc4\x87" => "c", "\xc4\x86" => "C", "\xc4\x99" => "e", "\xc4\x98" => "E", "\xc5\x82" => "l", "\xc5\x81" => "L", "\xc3\xb3" => "o", "\xc3\x93" => "O", "\xc5\x9b" => "s", "\xc5\x9a" => "S", "\xc5\xbc" => "z", "\xc5\xbb" => "Z", "\xc5\xba" => "z", "\xc5\xb9" => "Z", "\xc5\x84" => "n", "\xc5\x83" => "N", //ISO "\xb1" => "a", "\xa1" => "A", "\xe6" => "c", "\xc6" => "C", "\xea" => "e", "\xca" => "E", "\xb3" => "l", "\xa3" => "L", "\xf3" => "o", "\xd3" => "O", "\xb6" => "s", "\xa6" => "S", "\xbc" => "z", "\xac" => "Z", "\xbf" => "z", "\xaf" => "Z", "\xf1" => "n", "\xd1" => "N"); //$tekst = preg_replace( '#[^a-z0-9]#is', ' ', $tekst ); //$tekst = trim( $tekst ); //$tekst = preg_replace( '#\s{2,}#', ' ', $tekst ); $tekst = str_replace( ' ', '_', $tekst ); $tekst = str_replace( ' ', '', $tekst ); //$tekst = str_replace( '.', '', $tekst ); $tekst = str_replace( 'Ś', 's', $tekst ); $tekst = str_replace( 'Ż', 'z', $tekst ); $tekst = str_replace( 'Ź', 'z', $tekst ); $tekst = str_replace( ';', '', $tekst ); $tekst = str_replace( ',', '_', $tekst ); $tekst = str_replace( '/', '', $tekst ); $tekst = str_replace( '"', '', $tekst ); $tekst = str_replace( "'", '', $tekst ); $tekst = str_replace( '~', '', $tekst ); $tekst = str_replace( '|', '', $tekst ); $tekst = str_replace( ':', '', $tekst ); $tekst = str_replace( ';', '', $tekst ); $tekst = str_replace( '&', '', $tekst ); $tekst = str_replace( '%', '', $tekst ); $tekst = str_replace( '$', '', $tekst ); $tekst = str_replace( '!', '', $tekst ); $tekst = str_replace( '?', '', $tekst ); $tekst = str_replace( '_', '_', $tekst ); $tekst = str_replace( '--', '_', $tekst ); $tekst = str_replace( '-', '_', $tekst ); $tekst = strtolower($tekst); $tekst = strtr($tekst,$tabela); return $tekst; } function _pl($string) { $string = strtolower($string); $polskie = array(',', ' - ',' ','ę', 'Ę', 'ó', 'Ó', 'Ą', 'ą', 'Ś', 's', 'ł', 'Ł', 'ż', 'Ż', 'Ź', 'ź', 'ć', 'Ć', 'ń', 'Ń','-',"'","/","?", '"', ":", 'ś', '!','.', '&', '&', '#', ';', '[',']','domena.pl', '(', ')', '`', '%', '”', '„', '…'); $miedzyn = array('-','-','-','e', 'e', 'o', 'o', 'a', 'a', 's', 's', 'l', 'l', 'z', 'z', 'z', 'z', 'c', 'c', 'n', 'n','-',"","","","","",'s','','', '', '', '', '', '', '', '', '', '', '', '', ''); $string = str_replace($polskie, $miedzyn, $string); // usuń wszytko co jest niedozwolonym znakiem $string = preg_replace('/[^0-9a-z\-]+/', '', $string); // zredukuj liczbę myślników do jednego obok siebie $string = preg_replace('/[\-]+/', '-', $string); // usuwamy możliwe myślniki na początku i końcu $string = trim($string, '-'); $string = stripslashes($string); // na wszelki wypadek $string = urlencode($string); return $string; } $n=10; function getName($n) { $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $randomString = ''; for ($i = 0; $i < $n; $i++) { $index = rand(0, strlen($characters) - 1); $randomString .= $characters[$index]; } return $randomString; } function unique_multidim_array($array, $key) { $temp_array = array(); $i = 0; $key_array = array(); foreach($array as $val) { if (!in_array($val[$key], $key_array)) { $key_array[$i] = $val[$key]; $temp_array[$i] = $val; } $i++; } return $temp_array; } function object_to_array($data) { if (is_array($data) || is_object($data)) { $result = array(); foreach ($data as $key => $value) { $result[$key] = object_to_array($value); } return $result; } return $data; } function flat_array($a) { $it = new RecursiveIteratorIterator(new RecursiveArrayIterator($a)); return $it; } ?>