Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> znowu polskie fonty, str_replace i same problemy. Help!
codo
post 12.07.2005, 12:07:08
Post #1





Grupa: Zarejestrowani
Postów: 55
Pomógł: 0
Dołączył: 31.10.2004

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


Hej mam taki problem. User wpisuje w formularzu costam z polskimi znakami.
Chce otrzymac to co napisal bez polskich fontow wiec napisalem taka funkcje:
  1. <?php
  2.  
  3. function no_pl($string)
  4. {
  5.  
  6.  $pl=array(&#092;"ą\",\"ę\",\"ł\",\"ż\",\"ź\",\"ó\",\"ć\",\"ń\",\"ś\",\"Ą\",\"\",\"Ł\",\"Ż\",\"Ź\",\"Ó\",\"Ć\",\"Ń\",\"Ś\");  
  7. $no_pl=array(&#092;"a\",\"e\",\"l\",\"z\",\"z\",\"o\",\"c\",\"n\",\"s\",\"A\",\"E\",\"L\",\"Z\",\"Z\",\"O\",\"C\",\"N\",\"S\");
  8.  
  9. $string_nopl=str_replace($pl,$no_pl,$string);
  10.  
  11.  
  12. echo $string.&#092;" vs. \".$string_nopl.\"<Br>\";
  13. return $string_nopl;
  14. }
  15. ?>


A on przykladowo wypisuje: ĄŹŻŁŁaąłę vs. ĄŹZLLaąle
czyli zamienil tylko wybiorczo.
Strona jest kodowana w iso8859-2
Co robie zle?
Go to the top of the page
+Quote Post
mhs
post 12.07.2005, 13:39:53
Post #2





Grupa: Zarejestrowani
Postów: 764
Pomógł: 3
Dołączył: 30.04.2003

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


kod:
  1. <?php
  2. function noPl($str) {
  3. $patterns = array(
  4.  &#092;"/ą/\",
  5.  &#092;"/Ą/\",
  6.  &#092;"/ć/\",
  7.  &#092;"/Ć/\",
  8. );
  9.  
  10. $replacements = array(
  11.  &#092;"a\",
  12.  &#092;"A\",
  13.  &#092;"c\",
  14.  &#092;"C\",
  15. );
  16.  
  17. return preg_replace($patterns, $replacements, $str);
  18. }
  19.  
  20.  
  21. echo noPl('ĄĆąćĄąĆć');
  22. ?>


wynik:
Kod
ACacAaCc



manual: preg_replace" title="Zobacz w manualu PHP" target="_manual
Go to the top of the page
+Quote Post
codo
post 12.07.2005, 15:46:28
Post #3





Grupa: Zarejestrowani
Postów: 55
Pomógł: 0
Dołączył: 31.10.2004

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


Ok, dziekuje. Tylko dlaczego nie dziala str_replace?
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 22.06.2025 - 06:39