Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> kodowanie UTF-8 w pliku .txt za pomocą fwrite()
kokogdaczek
post 1.08.2007, 10:14:26
Post #1





Grupa: Zarejestrowani
Postów: 17
Pomógł: 0
Dołączył: 1.08.2007

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


witam!

Potrzebuję jakiegoś kodu w php za pomocą którego funkcja fwrite() zapisze w pliku .txt ciąg znaków w kodowaniu UTF-8.
Go to the top of the page
+Quote Post
pojas
post 1.08.2007, 10:47:58
Post #2





Grupa: Zarejestrowani
Postów: 53
Pomógł: 0
Dołączył: 31.03.2006

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


Może trzeba wykorzystać funkcję utf8_encode" title="Zobacz w manualu PHP" target="_manual, żeby zakodować treść, którą następnie zapiszesz do pliku. guitar.gif


Cytat(cutmaster at fearlesss dot com)
For those who, like me, lost a lot of minutes (hours) to understand why fwrite doesn't create a real utf-8 file, here's the explanation I've found :

I tried to do something like this :
  1. <?php 
  2. $myString = utf8_encode("Test with accents éčŕç"); 
  3. $fh=fopen('test.xml',"w"); 
  4. fwrite($fh,$myString); 
  5. fclose($fh); 
  6. ?>


For a mysterious reason, the resulted file shows the accent without the utf-8 conversion.

I tried the binary, mode, etc. etc. And finally I've found it :
It seems that fwrite NEEDS to have the utf8_encode function INSIDE its parameters like this, to understand it must create a non-text only file :
  1. <?php 
  2. $myString = "Test with accents éčŕç"; 
  3. $fh=fopen('test.xml',"w"); 
  4. fwrite($fh,utf8_encode($myString)); 
  5. fclose($fh); 
  6. ?>

Hope this will help


Ten post edytował pojas 1.08.2007, 10:51:28
Go to the top of the page
+Quote Post
kokogdaczek
post 1.08.2007, 10:48:47
Post #3





Grupa: Zarejestrowani
Postów: 17
Pomógł: 0
Dołączył: 1.08.2007

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


Wielkie dzięki, o to mi chodziło biggrin.gif
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: 27.05.2025 - 21:28