Cyrillic characters messed up in .php webpage - php

All my files with .php extension and Cyrillic encoding that worked fine for years got messed up. Probably because of PHP server upgrade by hosting provider.
To illustrate the problem I wrote the simplest possible file which cannot have any errors:
http://reverent.org/testencoding.php
For some reason webpage defaults to unicode when viewed in a browser. If you go to view -> Text encoding and select Cyrillic(Windows) everything gets fine.
In contrast, exactly the same file with .html extension is displayed correctly right away:
http://reverent.org/testencoding.html
Any idea?

Now, I'm no expert on this, but this seriously reminds me of the exact issue I had. So.. personal experience, here goes (I'm sure this might help someone):
My issue was that my files on the server were set to windows 1251 by default instead of UTF-8, which I needed.. this caused these little beasts to appear: � in place of every symbol that wasn't just a basic letter or something like that. Coincidentally this is what your example looks like. And the encoding is the same. I fixed it by accessing the files with WinSCP and just switching the files to UTF-8 manually... ironically your file shows pretty much what I saw on my website.
There must be better ways to do this than WinSCP, but to be honest, this is the only time I've had to do this manually, so this is exactly what I clicked there (after opening the file):
You could also try to fix it with a meta tag to tell the browser which charset to use, but the files might be getting deformed the moment you save them, if their encoding is wrong.
<meta charset="utf-8">
This might not work for you, but it did work for me, so there's hope :)
Hope it helps or at least points you in the right direction :)

I just put the php.ini file with this single line 'default_charset = "windows-1251"' in the directory with the files with Cyrillic encoding. This overwrites server's php.ini which sets default charset to UTF.
Now everything is fine: http://reverent.org/ru/testencoding.php

Related

PHP-Files magically serverd with a leading TAB

I got a weired behavior on my apache, php setup on debian system.
I tried to create an image with php and output it directly. It failed permanent and the browser said sth. like corrupt image file. After a lot of try and error arroun 3 hours I figured out that there is a TAB character added right at the beginning ob my image content, that does not belong there.
To proove that its part of the apache-php setup I created a test.php file, that just contains the letter 'a' and coppied this file to test.html. So Both files just contain the letter a.
You can see the resulting tab here:
http://www.activeroom.net/test.php
http://www.activeroom.net/test.html
and even on the base url itself - its a php-file, too.
Hope anybody can point me in the correct direction. Btw. on the console everything is fine: php test.php just returns an a. Maybe it is something about the Apache MimeTypes or headers?!
How stupid - there was a php-file prepended through the php.ini. That file had a tab at the end. Sometimes things are really messed up.

Accentuation problems with .php extension

I'm having some problems with accentuation and special characters on my website.
The problem only occurs on my webhosting (I've another website on the same hosting account, this one with the issue is in a sub folder, and the main website works well), on local with Wamp Server everything is OK.
So, my problem is: with .php extension accents aren't showed correctly but if I only change the file extension from .php to .html every accents are OK.
Edit:
I found my problem... I changed my code editor from notepad++ to sublime text and now it works.
It's strange because it was working well with wamp and in a free webhosting but not on my main hebhosting :/
Anyway, thank you very much for your help.
header('Content-type: text/html; charset=utf-8');
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
Note that, depending on where the text comes from, you might have to check some other things too (database-connection, source-file-encoding, ...) - i've listed a lot of them in one of my answers to a similar question.
In accordance with the similar issue
Charset=utf8 not working in my PHP page
you need to use ASCII character
And is your content type correctly set?
I searched for you: you can use this: é (ascii 130)

Charset of Apache (XAMPP) Server

I run a XAMPP Apache PHP Server on my Mac and I am facing the following problem: German special characters like ä ö ü and ß are displayed with strange questiontags instead of the correct symbol. I assume a misconfiguration of the server, since the files are all saved in UTF-8 and contain
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
In the -Tag of the files.
Anyone an idea how to get rid of those � ? I thought already of the httpd.conf , but there is already something like
#UTF 8
AddDefaultCharset utf-8
in it. The php.ini also includes
default_charset = "utf-8“
I really dont know how to proceed and my whole page looks not as nice as it should with those strange question tags...
Thanks for your Help!
Tim
I was having the same problem on my XAMPP local server and none of those things worked for me. The problem was in the transfer of data between mySQL (where all my foreign language looked good) and the server (where everything seemed good too). I was just missing this one statement in my.ini
"character_set_server=utf8"
which seems to affect data communication beetween server and mySQL
DON't change any other UTF-8 statements at the same time!
I run into the same problem after updating XAMPP.
I am using an other charset to display all kinds of characters used in countries like Holland, Germany, Norway, Sweden en Denmark. So my HTML contains:
Changing the default-charset into "windows-1252" did the trick for me.
Did you type these characters inside the source file? In this case, which encoding was the source file saved in?
With that meta tag "Content-Type" you are telling the browser to interpret the page as UTF-8 (despite whatever other value the server is returning). However, if you are saving the file in a different encoding that UTF-8, then it is displayed in the wrong way.
My suggestion is to check with your editor which encoding it is using, and tell it to use UTF-8 by default.
Open "my.ini" in "C:\xampp\mysql\bin\" directory.
Remove comment tag '#' from following code
init-connect=\'SET NAMES utf8\'
collation_server=utf8_unicode_ci
character_set_server=utf8
skip-character-set-client-handshake
character_sets-dir="C:/xampp/mysql/share/charsets"
It's Work for me
The PHP file was in ANSI format. I changed it to UTF-8 and everything started working. I did not change any code.
I add to my.ini config file xampp and resolve
[mysqld]
character-set-server = utf8
delete this line in file mysql/bin/my.ini
character-set-server=utf8mb4
collation-server=utf8mb4_general_ci
or change utf8mb4 to uft8
character-set-server=utf8
collation-server=utf8_general_ci

All line break removed in the server files

I am working on Wordpress.
After upload my project file in the live server and then for any certain changes, I found everything inside "styles.css" files comes into only one line.
Even what ever inside the "header.php" or "footer.php" also comes into only one line.
Then its become hardest to search any particular keyword.
Can anybody please suggest me, how do I prevent this kinda editing in the server?
I am using "NetBean 7" as the editor.
Your server has converted your file types to match the server's file system it sounds like. Your line breaks might be gone. Try opening them in Notepad++ or vim to be sure.
If you look at it in Windows under Wordpad it should work too.

New line before header()

I'm working with a custom made Joomla script that generates an image from a blob in a database. However, when we moved it from an Apache server to an IIS server, the script is breaking.
Upon investigation, it seems that now, there is a line break that is getting appended before the header function is being run (when I comment out the image portion, and do an echo "test";, test gets printed on line 2 of the source code.
I've gone through the script over and over again, and through the many files in the component, and can't seem to find out where this new line is coming from. At all.
I've tried using ob_start() and many similar functions, but nothing seems to work.
I'm completely out of ideas, and don't know where to turn.
Is there a way to trace what files are being called in the page, perhaps? Any thoughts on further steps?
Look out for additional whitespace at the end of PHP files. If a PHP file ends in more than a single return after the last ?>, that stuff gets printed regardless of where the file is/was included. That is a common error source in larger PHP projects and would meet your symptoms.
(To circumvent this, some have started with a coding standard that prohibits the last ?> in their source files, which is perfectly legal PHP.)
Be careful, maybe it's an encoding problem. Open the file with vim under linux to see if there an ^M or something like that.

Categories