f



Find out encoding of a file with php, and convert it to UTF-8 encoding

Hi all,

in my script I need to find out the encoding of a file and in case it
is not of the kind UTF-8 I need to convert it to that format.

Any hints??

Thanks
0
7/23/2006 9:26:59 AM
comp.lang.php 32646 articles. 0 followers. Post Follow

1 Replies
1049 Views

Similar Articles

[PageSpeed] 41

Matthias Langbein wrote:

> in my script I need to find out the encoding of a file and in case it is
> not of the kind UTF-8 I need to convert it to that format.

Something in http://www.php.net/manual/en/ref.iconv.php should be able to
help you.

HTH,
-- 
Benjamin D. Esham
bdesham@gmail.com  |  AIM: bdesham128  |  Jabber: same as e-mail
"Come to think of it, there are already a million monkeys on a
million typewriters, and Usenet is NOTHING like Shakespeare!"
                                                — Blair Houghton

0
bdesham (43)
7/23/2006 3:57:36 PM
Reply:

Similar Artilces:

Displaying UTF-8-encoded strings from MySQL with PHP
Hi there, I'm trying to migrate my project from ISO-8859-1 (Western Europe) to UTF-8. I *can* write special characters as regular text in my php- files, I can use special characters in echo-statements and I can even use special characters in .ini-files, load them, and display them. But when I load Strings with special characters from MySQL and display them, the string's "broken". I've tried many things: First of all, I use <?xml version=3D"1.0" encoding=3D"utf-8" ?> and <meta http-equiv=3D"Content-Type" content=3D"text/html;charset=3Dutf-8" /> in the markup. In the database I tried to set my table's collation to "utf8_general_ci". Also I tried the following functions: mysql_query("SET NAMES =E2=80=98utf8=E2=80=B2"); mysql_set_charset('utf8'); mb_internal_encoding("UTF-8"); all not at the very beginning of my script, but before I queried the database and before I printed the results. I still keep getting 'wierd' characters. Does anyone have an idea what I can do? Thanks, Lukas El 15/06/2011 12:18, Luke escribió/wrote: > I'm trying to migrate my project from ISO-8859-1 (Western Europe) to > UTF-8. I *can* write special characters as regular text in my php- > files, I can use special characters in echo-statements and I can even > use special characters in .ini-files, load them, and display them. But > when I load Strings wit...

How convert text file between locale encoding and UTF-8?
Dear Friends: Wondering that is there neat way to do "subject line" in Python? I am talking about Python 2.4 with Win32 extension installed. The locale can be any of ANSI defined, for example, zh_CN (CP936) or Korea (CP949) .......... I am not expert in Python, if you well note I will appreciate a lot. Rgds, David Xiao davihigh@gmail.com wrote: > Dear Friends: > > Wondering that is there neat way to do "subject line" in Python? I am > talking about Python 2.4 with Win32 extension installed. The locale can > be any of ANSI defined, for example, zh_CN (CP...

How can I get the encode of a txt file and convert it into UTF-8?
How can I get the encode of a txt file and convert it into UTF-8? I just want to find a class can do this in a simple way. And if I want to handled a UTF-8 string which class should it use? Can ofstream output files in UTF-8?How can I do it? Thanks. I think this is a I18N related question. U will get better answers in those group, Anyways, in windows we have widechartomultibyte(),.. apis to acheive conversions. ...

PHP encoded files
For the sole purpose of speed, not security, do php scripts that have been encoded with Zends Safeguard Suite run "faster" than non-encoded scripts ? "fartsniff" <fart@sniff.com> wrote in news:vjbskdpc0cch59@corp.supernews.com: > For the sole purpose of speed, not security, do php scripts that have > been encoded with Zends Safeguard Suite run "faster" than non-encoded > scripts ? They're supposed to. And benchmarking results I've seen show that they do (sorry, can't remember the URL, but it was an independent one). If you only ...

PHP Encoders
Hi there ! I am curretly looking for suitbale solutions for encoding PHP scripts after developing a couple of comercial applications in PHP. Has anybody made any experience with several encoders like IONCUBE, SOURCEGUARDIAN, ZEND, etc... so far? I just tested an evaluation copy of IONCUBE's php encoder which worked pretty fine. Runtime decoding is really fast and easy to implement. Has anybody some deeper insight into this issue? Thanks Jerry "Jerry" <eagleflyer2@lycos.com> wrote in message news:cthkrv0aj0h0cu04g592rr6bhqfdn29kpk@4ax.com... > Hi there ! > > ...

File in UTF-8 or local encoding
Hi everybody, how do I find out if a file I need to load is already UTF-8 or if it still needs conversion? Background: My Tcl application needs to source some sort of script, I have only minor control over this script. The scripts are written in basicly every possible encoding in the world. Before they can be used they need to be signed by a program I provide. At this point I can influence the encoding and I like to have the script stored in UTF-8. What I need to make sure is, that I don't try the conversion twice. Ideas anyone? -- Matthias Kraft Software AG, Germany (They that can give up essential liberty to obtain a little temporary) (safety deserve neither liberty nor safety. -- Benjamin Franklin) Matthias Kraft wrote: > Hi everybody, > > how do I find out if a file I need to load is already UTF-8 or if it > still needs conversion > > Background: My Tcl application needs to source some sort of script, > I have only minor control over this script. The scripts are written > in basicly every possible encoding in the world. Before they can be > used they need to be signed by a program I provide > > At this point I can influence the encoding and I like to have the > script stored in UTF-8. What I need to make sure is, that I don't try > the conversion twice. > > Ideas anyone? Not sure if i understand the problem correct: external script -> signing program -> final application -> denotes a conversi...

IIS could not find .php file, however it finds html files in the same dir
IIS could not find .php file, however it finds html files in the same dir..... http://localhost/test => the default.htm will be hit, no error http://localhost/test/test.php => 404 error not found( it exists in the dir) The security is set ok, something wrong with the php runtime?? Strange because my application on localhost/prog works smooth......... Can anybody help me? geronimi wrote: > IIS could not find .php file, however it finds html files in the same > dir..... > > http://localhost/test => the default.htm will be hit, no error > > http://localhost/tes...

Presenting UTF-8 encoded data in an e-mail with ISO encoding
Hi, We have a problem when trying to present data retrieved from SQL Server in an e-mail. We don't use SQL mail - we use JMail (in ASP code) and need to encode the message using ISO-8859-2. When ISO encoding is set in a message header, static text written in the message are OK, but data from DB (where they're stored in UNICODE) come without Polish characters. Using a VB or JScript that would convert UTF-8 strings into ISO-8859-2 might be a solution but maybe there is a "smarter" way? Have anybody come across similar problem? I'll be grateful for any hints. Best Regards, Daniel Slobodzian ...

Reading UTF-8 Encoded ASCII Files
I'm trying to read an ascii file that is UTF-8 encoded (according to Notepad) using the simple "Read Characters from File.vi". The displayed characters in Labview do not match the displayed characters in notepad. &nbsp; Files encoded in "ASCII" read just fine and match in both. &nbsp; What can I do to interpret the UTF-8 file as UTF-8 in a LabView Read? &nbsp; Thanks! If you open the file in Notepad you can choose "Save As", and then select the encoding at the bottom. Change it to ASCII, and then read in the new file in LV like normal. If you need this to be an automated thing, I would suggest changing the application that writes to the file, to do so in ASCII. Especially if your not going to get any characters that aren?t in the standard ASCII set. Sometimes it is the simplist things! Thank you. These are playlists generated with Windows Media Player. The one's burned from Celtic CD's are sometimes UTF-8. &nbsp; Thanks again for the suggestion! &nbsp; ...

UTF-8 file reading and writing for PHP
I'm creating a page that: - accepts user input in whatever language - saves that input to a file - reads the file and displays the original input The following code successfully writes the user input to a file (when I open the file, it's in the correct font), but I can't get PHP to read the file and display the correct characters. HTML --------------- Form <FORM name=saveform method=post action="wiki.php"> File: <TEXTAREA name=thetext rows=20 cols=30></TEXTAREA> </TEXTAREA> <INPUT type=submit> <INPUT type=hidden name=action value=&quo...

Printing a UTF-8 encoded XML file
Hi, I am computing an XML file with all necessary tags, to be used in dedicated XML software. I am computing it as a text file but don't know how to do to save it to the disk UTF-encoded. strConv() with constant = 64 does not work, because the default code page of the system is UTF-16 and the XML editor I am using, XMLSpy, expects structured text when importing text files (so it cannot import my tagged files). The only way I have found out to convert to UTF-8: copy / paste the text from a text editor into XMLSpy, and save. But the procedure would be more elegant without that step. What I am looking for is: automation. Can anybody help with this, please? Reto Hadorn SIDOS On 10 Nov 2005 00:58:14 -0800, "reto.hadorn@sidos.unine.ch" <reto.hadorn@sidos.unine.ch> wrote: >Hi, > >I am computing an XML file with all necessary tags, to be used in >dedicated XML software. I am computing it as a text file but don't know >how to do to save it to the disk UTF-encoded. strConv() with constant = >64 does not work, because the default code page of the system is UTF-16 >and the XML editor I am using, XMLSpy, expects structured text when >importing text files (so it cannot import my tagged files). > >The only way I have found out to convert to UTF-8: copy / paste the >text from a text editor into XMLSpy, and save. But the procedure would >be more elegant without that step. What I am looking for is: >automation. > >Can ...

PHP does not parse .PHP files
I have this problem with PHP that someone might be able to help. With CLI, I am able to execute my .php files. For example, if I type "php phpinfo.php" , this works fine on my system. If I put the phpinfo.php file is in /var/www/html and I try to access it through the browser, I get the content of the file and not the execution of the file. Instead of display the info of PHP, I got the text of the file as: <?php phpinfo(); ?> Why? Thanks Phong Ho wrote: >I have this problem with PHP that someone might be able to help. > >With CLI, I am able to execute my ....

"-encoding identity" vs "-encoding binary" and UTF-8 data
This question comes from the discussion in Tcl Bug #411825: http://sourceforge.net/tracker/?group_id=10894&atid=110894&func=detail&aid=411825 Can anyone explain the behavior I'm seeing, in the comment I added on 2003-08-28 07:58? Why is the behavior different between "-encoding binary" and "-encoding identity"? -- Dossy -- Dossy Shiobara mail: dossy@panoptic.com Panoptic Computer Network web: http://www.panoptic.com/ "He realized the fastest way to change is to laugh at your own folly -- then you can let go and quickly move on." (p. 70) Hi Dossy, Dossy <dossy@panoptic.com> writes: > This question comes from the discussion in Tcl Bug #411825: > > http://sourceforge.net/tracker/?group_id=10894&atid=110894&func=detail&aid=411825 > > Can anyone explain the behavior I'm seeing, in the comment I added > on 2003-08-28 07:58? Why is the behavior different between > "-encoding binary" and "-encoding identity"? You wrote there: > when I set stdout encoding to binary, it should give me the raw > UTF-8 (9 bytes) and not the transcoded ISO-8859-1 representation (8 > bytes), right? No. With encoding binary your strings will all be treated as binary data "without interpretation". The hook here is the expression "binary data", what is that in Tcl? First a definition of normal strings. Normal strings...

Emacs can't edit files encoded utf-8
Out of the blue, while editing a series of files, all of which had as their first line: <?xml version="1.0" encoding="UTF-8"?>, emacs23 decided it could not load the file: Debugger entered--Lisp error: (wrong-type-argument number-or-marker-p nil) font-lock-fontify-keywords-region(1 45 t) font-lock-default-fontify-region(1 45 t) font-lock-fontify-region(1 45 t) byte-code("ŠÃ ĎÅed #ˆÆ ˆÇ‰+‡" [save-match-data-internal verbose font-lock-fontified match-data ((byte-code "ÁÂ\"‡" [save-match-data-internal set-match-data evaporate] 3)) font-lock-fontify-region font-lock-after-fontify-buffer t] 4) font-lock-default-fontify-buffer() font-lock-fontify-buffer() font-lock-mode-internal(t) font-lock-default-function(t) font-lock-mode() turn-on-font-lock() turn-on-font-lock-if-desired() global-font-lock-mode-enable-in-buffers() global-font-lock-mode-check-buffers() run-hooks(find-file-hook) after-find-file(nil t) find-file-noselect-1(#<buffer test-a.html> "/storage/USS-Irex/mirror/docs/test-a.html" nil nil "/storage/USS-Irex/mirror/docs/test-a.html" (1127907 2053)) find-file-noselect("/storage/USS-Irex/mirror/docs/test-a.html" nil nil nil) find-file("/storage/USS-Irex/mirror/docs/test-a.html") command-line-1(("Sans" "Mono-9" "/storage/USS-Irex/mirror/docs/test-a.html")) command-line() ...

encoding="UTF-8" being deleted when generating file from DOM
I have an XML Snippet <?xml version="1.0" encoding="UTF-8"?> and when I convert the entire xml file to a DOM and then generate a new file from the DOM, results in <?xml version="1.0"?>. Any thoughts? My sample code snippet is: DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(in.xml); FileWriter file = new FileWriter(out.xml); // Create an XMLInputStream using the DOM we've changed XMLInputStreamFactory ifactory = XMLInputStreamFactory.newInstance(); XMLInputStream istream = ifactory.newInputStream(doc); // Create an XMLOutputStream to generate a new output file // using the file created earlier XMLOutputStreamFactory ofactory = XMLOutputStreamFactory.newInstance(); XMLOutputStream output = ofactory.newOutputStream(new PrintWriter(file,true)); output.add(istream); output.flush(); output.close(); Mike Kennedy wrote: > I have an XML Snippet <?xml version="1.0" encoding="UTF-8"?> and when I > convert the entire xml file to a DOM and then generate a new file from > the DOM, results in <?xml version="1.0"?>. > Any thoughts? That is allowed, encoding UTF-8 or UTF-16 has to recognized by any XML parser without the encoding being specified. -- Martin Honnen http://JavaScript.FAQTs.com/ Martin, thanks. But I'm wondering why the encod...

Is a PHP variable supposed to be seen in a .js file included into a .php file
Is a PHP variable supposed to be seen in a .js file included into a .php file? I have a client side javascript code stored in a .js file which is included into a PHP file using <script src="filename.js></script> This code initialises a Javascript variable var u="string"; The string is supposed to be the value of $HTTP_HOST So, when initialise this variable like var u=<? echo $HTTP_HOST;?>; I sterted getting a javascript message Syntax Error Am I doing something wrong, or PHP variables are not seen in included js files? aa wrote: > Is a PHP variable supposed to be seen in a .js file included into a .php > file? > > I have a client side javascript code stored in a .js file which is included > into a PHP file using > <script src="filename.js></script> > > This code initialises a Javascript variable > var u="string"; > > The string is supposed to be the value of $HTTP_HOST > > So, when initialise this variable like > > var u=<? echo $HTTP_HOST;?>; > > I sterted getting a javascript message Syntax Error > > Am I doing something wrong, or PHP variables are not seen in included js > files? js files are not parsed for PHP code unless you specifically tell the webserver to do so. Therefore, "var u=<? echo $HTTP_HOST;?>;" in the .js will error since the browser doesn't know what to do. -- Justin Koivisto - spam@koiv...

xharbour doesn't compile UTF-8 encoded files (with BOM)
Unicode encoding UTF-8 is standard string encoding in many modern widget toolkits (GTK++, next version of wxWidgets). So we need UTF-8 enabled editors and compilers. Harbour compiler allready accepts UTF-8 with BOM encoded files. Of course both compilers accept UTF-8 without BOM (utf-8 cookie), but i have to set encoding type in my editor every time. ...

Open .php file with PHP Designer 2007 by clicking the file in XP
In windows XP, I want to be able to click on a .php file and have it opened in PHP Designer 2007, Or right-click on it and have an "edit" menu option presented to me. I know how to tweak the registry to do this in general, but what would the command line look like in this specific case ? PHP Designer does not do this automatically. It is as if the program does not allow commandline options. It only opens with the last file used or a menu of recently opened files. ...

want to get content of one php file in another php file
i have one php file having content Contents of ex1.php file <body> <?php $content = "c://webserver/www/abc.php"; $handle = fopen($content, "r"); echo fread($handle,filesize($content)); ?> </body> this is reading abc.php file in which i m simply using an echo statement. When i execute ex1.php file i cant see the php statement of abc.php file content of abc.php file is <?php echo "hello";?> sarika wrote: > i have one php file having content > > Contents of ex1.php file > <body> > <?php > $content = "c://webserver/www/abc.php"; > $handle = fopen($content, "r"); > echo fread($handle,filesize($content)); > ?> > </body> > this is reading abc.php file in which i m simply using an echo > statement. When i execute ex1.php file i cant see the php statement of > abc.php file > > content of abc.php file is > <?php echo "hello";?> That's interesting, I've found out that it's the browser that's hiding <?php ?> tags within .phpx pages. Probably to avoid short tags scripts (on a server that doesn't allow them) from getting leaked by visitors who don't know about this browser trick, until the dev' realizes his error. Not a good thing, IMO; dev's should take care, themselves, and it's still not secure since the hidden string is still in the rendered source. And now we don't know how ...

Parsing a php include (which also contains php code)
Hello, I am using the <?php include() ?> statement on my website for organizational purposes. However, one of my includes contains some PHP code. Is there any way for the server to actually parse the include? I've tried this before, and it did not parse the include. Rather, it included the file as just plain ASCII. ======================= /*EXAMPLE 1*/ /*index.php*/ .... <?php include('global/includes/footer.inc') ?> .... /*footer.inc*/ .... <p>&copy 1993-<?php echo date("Y") ?> Kingswood School. All rights reserved.</p> .... /*EXAMPLE 2*/ /*index.php*/ .... <?php include('global/includes/lastmod.php') ?> .... /*lastmod.php*/ .... <?php echo "This file was last modified: "; echo strftime("%A %B %d %Y"); include('whateverfilename.inc'); ?> ============================= I would like to be able to parse the include if it has php code, and in some cases, create nesting includes (an include within an include). Is this even possible? Any ideas? Any help is certainly appreciated. Thanks! Steven Borrelli Web Developer Kingswood School Steven Borrelli wrote: > Hello, > > I am using the <?php include() ?> statement on my website for > organizational purposes. However, one of my includes contains some > PHP code. Is there any way for the server to actually parse the > include? I've tried this before, and it did not parse the in...

Text file encodings in OS-X (ISO Latin1 8859 vs UTF-8)
Out of curiosity, when I save a text file in TextEdit, I am given the chance to specify the text encoding (ISO 8859-1 Latin1, UTF-8 and amny others) in the "save as" menu option. How/where is this stored ? From the command line, is there a way to see and possibly change the text encoding associated with a file ? Recently used PHP to download data from the CRTC web site which the HTTP headers specified as UTF-8 but PHP has great problems dealing with accented characters both when data read directly via HTTP or if the HTML files were first stored locally as text files. And now, I have TextEdit telling me it can no longer save a text document because I pasted text that probably contains characters not possible in latin-1 so I have to save-as UTF-8. I'd like to have a better understanding on how text files are processed under OS-X. On 2012-12-18 20:43:25 +0000, JF Mezei <jfmezei.spamnot@vaxination.ca> said: > Out of curiosity, when I save a text file in TextEdit, I am given the > chance to specify the text encoding (ISO 8859-1 Latin1, UTF-8 and amny > others) in the "save as" menu option. > > How/where is this stored ? From the command line, is there a way to see > and possibly change the text encoding associated with a file ? > > Recently used PHP to download data from the CRTC web site which the HTTP > headers specified as UTF-8 but PHP has great problems dealing with > accented cha...

Modify a php file(model) with php
I have an invoice model on my server! and i want to replace some field(like adresse, phone, price, VAT, ....) do you know a tools or class that allows those kind of manipulations Thanks you Yoni Yoni Alhadeff a �crit : > I have an invoice model on my server! and i want to replace some field(like > adresse, phone, price, VAT, ....) > > do you know a tools or class that allows those kind of manipulations > > Thanks you > > Yoni > > Couldn't you replace field with var and have them set when including your template (it become one in fact) ? I didn'...

When does the php interpreter loads the php file?
Hi All, I'm wondering three facts about php, apache and apache module. 1.How can i differentiate the php intepreter if it's running as a apache module or as cgi? 2.When does the php interpretor loads the php file to main memory? 3.and till when it keeps the php file on memory? - in my experience only after installing Zend it caches the php file. Thak you *** Kim Gijung wrote/escribi� (20 Oct 2004 00:03:35 -0700): > 1.How can i differentiate the php intepreter if it's running as a > apache module or as cgi? If I recall correctly phpinfo() calls it "Server API&qu...

php assembly of multiple php files
I am trying to combine multiple php pages into 1. Basically I have created a shell page and then a seperate php file for each form to be included within the shell. The problem I am having is that when a user submits one of the forms the main shell and the other php files POST values are all returned as NULL and I only get the values pertaining to the form that was submitted?. If all the files were combined into one very long php file, I would get all the POSTs returned how can I do the same but with multiple files? When you submit an include, do the POST values not get passed back to the Main calling page? Thank you, QB Question Boy wrote: > I am trying to combine multiple php pages into 1. > > Basically I have created a shell page and then a seperate php file for > each form to be included within the shell. > > The problem I am having is that when a user submits one of the forms > the main shell and the other php files POST values are all returned as > NULL and I only get the values pertaining to the form that was > submitted?. If all the files were combined into one very long php > file, I would get all the POSTs returned how can I do the same but > with multiple files? > > When you submit an include, do the POST values not get passed back to > the Main calling page? > > Thank you, > > QB This has nothing to do with PHP - it's how HTML works. The browser will only send the data for the form being subm...

Web resources about - Find out encoding of a file with php, and convert it to UTF-8 encoding - comp.lang.php

Encoding (memory) - Wikipedia, the free encyclopedia
Visual, acoustic, and semantic encodings are the most intensively used. Other encodings are also used. Acoustic encoding is the encoding of auditory ...

Twitter image encoding challenge
If a picture's worth 1000 words, how much of a picture can you fit in 140 characters? Note : That's it folks! Bounty deadline is here, and after ...

【medical-news】Genetic Variation in NR1H4 Encoding the Bile Acid Receptor FXR - 医药生命科学动态跟踪 -丁香园论坛
Context: Bile acid signaling via farnesoid X receptor (FXR) regulates glucose and lipid levels, fat mass, and hepatic steatosis in animal models.Objective: ...

HandBrake Open Source video transcoder v0.10 released with hundreds of new features including H.265 and ...
... can be used for transcribing many different types of files/codecs to almost any other. Today’s headliner updates include H.265 and VP8 encoding. ...

CJK Type - CJK Fonts, Character Sets & Encodings. All CJK. All of the time.
As I wrote nearly a year ago , the Adobe-Identity-0 ROS is useful for building special-purpose fonts, especially CJK ones whose glyph coverage ...

Link Encoding Goes Mobile With Deep Links From Bitly
... Facebook and Google have been competing to bring the best solution for tracking deeplinks . This week, Bitly announced its own linking encoding ...

Encoding Articles - AppAdvice iPhone/iPad News
Latest Encoding Articles - AppAdvice iPhone/iPad News

AirMovie - Enjoy the videos in your PC anytime, anywhere with NO ENCODING!!
Holen Sie sich „AirMovie - Enjoy the videos in your PC anytime, anywhere with NO ENCODING!!“ im App Store. Sehen Sie sich Screenshots, Bewertungen ...

More tips on encoding video for Apple TV and iPod, from us to you
Apple tells video podcasters how to encode their content, which is also useful …

Handbrake 0.9.6 gives some, takes some encoding features
The Handbrake Project has announced an update to its open-source, cross-platform video transcoding utility. Handbrake 0.9.6 includes new and ...

Resources last updated: 3/23/2016 10:35:57 PM