Results 1 to 3 of 3
  1. #1

    PHP - Polish characters encoding UTF-8

    Hello, I've got problem with encoding Polish language in PHP.

    My PHP code (index.php):
    HTML Code:
    <!DOCTYPE html>
    <html>
    <meta charset="UTF-8">
    <head></head>
    <body>
    	<?php
    		echo ("łąśćź");
    	?>
    </body>
    </html>
    File is saved as index.php with encoding UTF-8.
    When I open index.html with code below everything is ok.
    HTML Code:
    <!DOCTYPE html>
    <html>
    <meta charset="UTF-8">
    <head></head>
    <body>
    łąśćź
    </body>
    </html>
    What can I do to display Polish characters correctly in PHP?

  2. #2
    Assuming that your content is not retrieved from a database, have you made sure that your server is sending out a UTF-8 header? Check the header from your server to make sure. If you are using Firefox, you can check by navigating to your page and selecting Tools -> Web Developer -> Inspector. When in the Inspector panel, click the "Network" tab, reload your page, and then click on the main file in the list and on the right side look at the "Response Headers". It should say something like "Content-Type: text/html; charset=utf-8".

    You have to make sure your server is sending a UTF-8 header. I'm not sure if that is your problem, but that is the first place to look. You can test by placing this line before your echo statement:

    Code:
    header('Content-Type: text/html; charset=utf-8');
    Also, if you are extracting data out of a database, you should run a set_charset("utf8") statement or run a "SET NAMES utf8" query after you connect to the database but before you execute any other queries.

  3. #3
    What's the off-chance your HTTP server is negotiating your character set for you? For Apache, if you have admin rights to edit the master config, httpd.conf, then add:
    Code:
    AddDefaultCharset UTF-8
    If you don't have permission to do this, then you may be able to override via a .htaccess file:

    Code:
    IndexOptions +Charset=UTF-8
    Nginx is a little different. Edit nginx.conf and add
    Code:
    charset UTF-8;
    You could always use the web developer tools in Chrome or Firebug in Firefox to inspect the HTTP headers of your request. Under Response Headers you should see something along the lines of,

    Code:
    Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0
    Connection:close
    Content-Type:text/html; charset=UTF-8
    Failing this - and this is unlikely - if you're uploading via FTP, do the FTP client and server support UTF-8?

Similar Threads

  1. Problem with PHP Encoding (arabic characters)
    By y0us3f in forum VPS Hosting
    Replies: 2
    Last Post: 02-02-2011, 06:13 PM
  2. mysql 4.1.15 and utf-8 encoding
    By orbitz in forum Programming Discussion
    Replies: 1
    Last Post: 04-13-2006, 12:58 AM
  3. PHP automatically converts characters to UTF-8
    By Platypus101 in forum Hosting Security and Technology
    Replies: 0
    Last Post: 09-01-2005, 09:00 PM
  4. encoding problem- UTF-8?
    By zekoslav in forum Hosting Security and Technology
    Replies: 2
    Last Post: 01-07-2005, 07:01 PM
  5. PHP Help: Encoding/Decoding characters
    By zahid in forum Programming Discussion
    Replies: 2
    Last Post: 05-30-2004, 03:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •