Jump to content

How to create a file with default charset utf-8


giba

Recommended Posts

Hi there, guys.

 

Hey I got an issue today.

 

I am building a system that creates files on the fly

But I must use utf-8 as default charset,

because it is used for the most application files.

In fact I am doing the basic task.

 

He is the basic code:

 

if(file_exists($file)) {

$error = "This is already exists!";

} else {

/**

* Open the file

*/

  $f= fopen($file,'x+');

       

  /**

* Write the new content

*/

  fwrite($f,$content);

 

/**

* Close the file

*/

fclose($f);

}

How could I generate this file in utf-8?

 

 

How could I generate this file in utf-8?
Assuming that the actual data you want to write includes multi-byte characters, simply write the data to that file.

It's the external applications used to read that file that need to support utf-8.

Well, I have done this yet!

But to make it clear,

When the server creates a file on Windows it does as ANSI.

On Linux it does as UTF-8.

 

So when I include a ANSI file inside a UTF-8 it gerenates strange characters.

 

The workaround is manually converting it to utf-8 on Windows with notepad++,

on Linux it's all right.

 

But this is an important issue because the application must be cross platform.

 

I will let it as it is!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.