How to save a php file with utf-8 encoding

1,291 views
Skip to first unread message

Odilon Cenamo

unread,
Jun 14, 2011, 4:24:33 PM6/14/11
to scite-i...@googlegroups.com
Hi,

I couldn´t understand (again) the SciTE documentation.

It says:

SciTE will automatically detect the encoding scheme used for Unicode files that start with a Byte Order Mark (BOM). The UTF-8 and UTF-16 encodings are recognised including both Little Endian and Big Endian variants of UTF-16.

UTF-8 files will also be recognised when they contain a coding cookie on one of the first two lines. A coding cookie looks similar to "coding: utf-8" ("coding" followed by ':' or '=', optional whitespace, optional quote, "utf-8") and is normally contained in a comment:

# -*- coding: utf-8 -*-
For XML there is a declaration:
<?xml version='1.0' encoding='utf-8'?>

For other encodings set the code.page and character.set properties.


I try this. I put into the SciTEGlobal.properties this line:

code.page=65001

and I set the Files / Encoding to "UTF-8" propertie.

but when I close SciTE and open again, the Files / Encoding set returns to "Code Page Propertie".

Whell, the Code Page propertie is 65001, I suppose this is UTF-8... but Not !!

The UTF-8 is working only if I set one of the two first lines of my source file with a comment:

//~ # -*- coding: utf-8 -*-     (for php)

or

# -*- coding: utf-8 -*-    (for properties files and something similar.)

Does anybody know how to instruct SciTE in order to save "ALL source files" with UTF-* encoding, or then,to save "ALL PHP source files" with UTF-8 encoding ?

Thank you,

Odilon




Neil Hodgson

unread,
Jun 14, 2011, 10:28:45 PM6/14/11
to scite-i...@googlegroups.com
Odilon Cenamo:

> I try this. I put into the SciTEGlobal.properties this line:
>
> code.page=65001
>
> and I set the Files / Encoding to "UTF-8" propertie.
>
> but when I close SciTE and open again, the Files / Encoding set returns to
> "Code Page Propertie".
>
> Whell, the Code Page propertie is 65001, I suppose this is UTF-8... but Not
> !!

What evidence do you see that the file is not UTF-8?

Neil

Odilon Cenamo

unread,
Jun 14, 2011, 10:36:41 PM6/14/11
to scite-i...@googlegroups.com
Because the special characters that I use, when I save the file with UTF-8 it appears OK, when I close the SciTE and reopen it, the special characters appears totaly wrong.

When I put the comment line:


//~ # -*- coding: utf-8 -*-

The special characters appear OK.

The "bug" is that SciTE don´t respect the Code Page propertie.
(this is what seems to be happening)

The two properties I'm using are:

code.page=65001
character.set=204




--
You received this message because you are subscribed to the Google Groups "scite-interest" group.
To post to this group, send email to scite-i...@googlegroups.com.
To unsubscribe from this group, send email to scite-interes...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/scite-interest?hl=en.


Lorenzo Donati

unread,
Jun 14, 2011, 11:54:26 PM6/14/11
to scite-i...@googlegroups.com
On 15/06/2011 4.36, Odilon Cenamo wrote:
> Because the special characters that I use, when I save the file with
> UTF-8 it appears OK, when I close the SciTE and reopen it, the special
> characters appears totaly wrong.
>
> When I put the comment line:
>
> *//~ # -*- coding: utf-8 -*-
> *

>
> The special characters appear OK.
>
> The "bug" is that SciTE don´t respect the Code Page propertie.
> (this is what seems to be happening)
>

Are you sure you are entering special characters AFTER you save and
reload your file with the "coding: utf-8" cookie on top?

I had a seemingly similar issue.

Try this exact sequence:

1. create a new file
2. put -*- coding: utf-8 -*- (the so called "encoding cookie") in a
comment on the first line
3. save the file with a name of your choice
4. close and reopen the file (or just use "revert")
5. write some special char (in lines after the encoding cookie) and save
and close again
6. reopen the file and see if the special chars are there as you typed them

Best regards
-- Lorenzo

Odilon Cenamo

unread,
Jun 15, 2011, 3:05:32 PM6/15/11
to scite-i...@googlegroups.com
Hi Lorenzo,

When I put the encoding cookie into the php source files (or html files, or jsp, etc..) the things work OK, but I want to tell SciTE by properties, with the lines:

code.page=65001
character.set=204

into the propertie file (SciTEGlobal.properties or html.properties or php.properties, etc.., etc...)

Why not work that way? In the documentation says it should work.
Or so I'm not understanding what the documentation means.

I already found the solution so that my files are saved with UTF-8 encode - but only managed this by placing the cookie on the first or second line of the source file. What I wish, however, is to ask the SciTE that records ALL my php files, html, jsp, etc ... as always UTF-8, with no obligation to put the cookies in the beginning of them.

Thanks
for your tips.


Regards,

Odilon



--

Neil Hodgson

unread,
Jun 15, 2011, 7:29:24 PM6/15/11
to scite-i...@googlegroups.com
Odilon Cenamo:

> Because the special characters that I use, when I save the file with UTF-8
> it appears OK, when I close the SciTE and reopen it, the special characters
> appears totaly wrong.

That isn't what happens to me.

1) Clear out SciTEUser.properties so there is nothing in it.
2) Add these lines to SciTEUser.properties:
code.page=65001
character.set=204
3) Create a New file
4) Type some Russian characters: йцу
5) Save as x.php
6) Close SciTE
7) Open SciTE
8) Open x.php
9) See йцу

Neil

Odilon Cenamo

unread,
Jun 15, 2011, 7:44:35 PM6/15/11
to scite-i...@googlegroups.com
I download again the same version (2.21) and copied the original properties files SciTEGlobal, html and download again the php properties and api files.

I retraced
my personal properties and now everything is going well!
Apologies to all, is it possible that I have damaged some files after a series of changes and I could not discover the error.

Thank you
all for the tips.


Is it important to download the latest release - 2.26?
Can I download this release and just replace the executables and dll's?

Thanks again.

Odilon



2011/6/15 Neil Hodgson <nyama...@gmail.com>

  Neil

Neil Hodgson

unread,
Jun 15, 2011, 7:54:19 PM6/15/11
to scite-i...@googlegroups.com
Odilon Cenamo:

> Is it important to download the latest release - 2.26?

The differences are listed on
http://www.scintilla.org/ScintillaHistory.html. It is up to you
whether you think its worth while upgrading since it will depend on
what you think is important.

> Can I download this release and just replace the executables and dll's?

You should only put your modifications in user properties. That
makes it easy to install a new version over the old version by just
copying all the new files over the old files.

Neil

Odilon Cenamo

unread,
Jun 15, 2011, 8:03:05 PM6/15/11
to scite-i...@googlegroups.com
Ahhhhh... OK Neil !!!

I have made ​​changes in the SciTEGlobal.properties and html.properties (mostly).

> You should only put your modifications in user properties. That
makes it easy to install a new version over the old version by just
copying all the new files over the old files.

I will follow your recommendation !

Thank you very much.


Regards,

Odilon



  Neil

Reply all
Reply to author
Forward
0 new messages