I have tried a few days,but I can't solve it.....

Thanks in advance...

    Is simply just use the: utf8_encode()

    I used it to encode my responces from PHP to flash so the flash can use especial characters like á é í ó ú ñ etc....

      I don't mean like this.....

      utf8_encode() can encode a string,but it is useless when I want to create a file of UTF-8 format...

      for example:
      Now I want to create a file named "user.cell" with function fopen(),But in any case the file will be of txt Format..not UTF-8.

      Thank you all the same...

        Hi,

        what kind of data do you want to store in the file ?

        Thomas

          Can't you just use utf8_encode() and save the resulting UTF8-encoded string in the file?

            I can convert the string to UTF-8 format with the function UTF8_encode(), But I can't create a file of UTF-8 to store it......
            Can you guys catch my meaning?
            thank you all the same.....

            by the way:I am a newbie,so if I make some troubles to you,I just can say sorry..

              Ok,

              just to understand ... I created some text with german umlauts, converted it to UTF-8, opened a file for writing and wrote the string to the file. The contents were UTF-8 encoded. I opened the file with an editor that doesn't support UTF-8 and saw special chars. I opened the file with an editor that supports UTF-8 and the contents of the file looked fine (with german umlauts).

              Ok ... I thought a little bit about that ...

              There's a difference between a text file containing UTF-8 text and a UTF-8 file which contains UTF-8 text, too, but additionally has a special signature and maybe an encoding header at the beginning.

              Do you want to create such a file with signature/header information ?

              Thomas

                en...
                For my English is too weak,I can't understand all you said..

                But I can catch your general meaning....🙂

                I want to create a UTF-8 file and store UTF-8 string in it..

                now I have a mothed to solve this problem...as follow:
                (But I want to see other solutions)

                First,I create a file(Here I call it model.php) of UTF-8 format with a tool(such as EditPlus).
                Then I use the model.php file and the following script to create other files...

                <?php
                $file_name="new.php";
                copy("model.php",$file_name);
                $handle=fopen($file_name,"wb");
                //......some scripts to write file......
                ?>
                

                Have I explained clearly?🙂Pardon my poor English.....

                  Ok,

                  please post a UTF-8 file you created with the editor.

                  Thomas

                    just a utf-8 file with any contents.......

                      I don't see why this is a problem.

                      Files do not care what is inside them.

                      Create a UTF-8 string.

                      Open a file. Write the data. Close the file.

                      Done.

                      There is no such thing as a "UTF-8 file" type in Unix/Linux/POSIX. It's a method of encoding an extended character set in an 8-bit representation. It is not a MIME type.

                        I can't browse normally the page created like what you said when I used Chinese chars in this page...while I can browse another page created as my method...

                          by the way...the browser is in the cellphone...

                            Hoooo I know what happens 😃, both of you are right and wrong 🙂 (yelvington & surfchen)

                            Ok while I was investigating about UTF8, I find some reference where I read that SOME programs that reads UTF8 files request them to be saved in UTF8 format, an UTF8 format file is just a TEXT file, but it starts with some characters, that makes the difference, and makes it an UTF8 file. Also I read that it was'n a standard and I don't bookmaked that page 🙁, so I can't tell you where to go and search 🙁

                            I have a solution to your problem but I dont know really if it will work WITH YOUR CELL BROWSER, so try this 😃

                            <?
                            header("Content-Type: text/plain; charset=utf-8");
                            echo utf8_encode($yourString);
                            ?>

                            The logics and the Protocols standards says that IT HAS TO WORK! Try that in your browser.

                            Also I include an UTF8 file in this post, just read it character by character ( I wrote that file in an UTF8 editor so IT teorically will had that extra characters! 😃 )

                            The file I included has the words: "Hola niño como estas" with out the quotes. So any other character you find are the standards for an UTF8 file. The only especial character there is the ñ, so analize it and se where's the secret, and post it here for future reference.

                              Normal characters that are part of the ASCII set are encoded EXACTLY the same way in UTF-8. There is nothing special about the file to indicate that UTF-8 encoding is being used. In fact, UTF-8 is the officially recognized encoding method for XML.

                              Multibyte sequences kick in ONLY when you are referring to characters that are not in the original ASCII set.

                              Chinese, whether simplified or traditional, requires these multibyte sequences. A good explanation is here:

                              http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8

                              I think the same thing in simplified Chinese is here:

                              http://www.linuxfans.org/nuke/modules.php?name=News&file=article&op=view&sid=1749

                              But again, it's not at the file level. It is something that happens in the character stream when characters not in the basic ASCII set are required.

                              The cool thing about UTF-8 is that it provides one format that works with just about everything -- English, French, Spanish, Chinese, Russian -- in a single file, and since everything is encoded in 8-bit bytes, existing tools can be made to work with it. Vim will process UTF-8 just fine.

                              I suspect Dragnovich is right that surfchen's browser problems are related to an HTTP mime type but without knowing the browser's actual requirements it's difficult to say. If the utf-8 charset doesn't work, try GB2312.

                                I found a page dealing with the UTF-8 signature, too (I didn't bookmark it,too and wasn't able to find it again ... just google for UTF-8 signature) The most common signature for UTF-8 files is

                                EF BB BF

                                Oen a file and write that bytes at the beginning of the file like e.g.:

                                  $fp = fopen("utftest2.txt","wb");
                                  fwrite($fp,pack("CCC",0xef,0xbb,0xbf)); 
                                

                                Then add the utf-8 encoded string to the file. Any UTF-8 capable application/browser should be able to read that file and will ignore the three bytes when displaying the contents of the file. Some applications require UTF-8 files to have the signature.

                                One way to set the encoding is sending a header like the one Dragovich posted. Another way is to change the settings of your browser to select the character encoding automatically. Both ways worked with my browser.

                                Thomas

                                  Write a Reply...