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?

 

 

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

Sure, that's all right now!

I haven't seen this before because I didn't looked at the note inside the PHP manual  ::).

The little I used file handling with PHP was that simple.

But, yes, in fact it now works perfectly.

Thanks.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.