I'm trying to output Chinese characters and Pinyin from my Game.php file.
In my Game.HTML file, just using <meta http-equiv="content-type" content="text/html; charset=utf-8" /> works fine.
But in my Game.PHP file, it does not. So I tried following these to get it to work:
1) How to best configure PHP to handle a UTF-8 website
2) UTF-8 all the way through
At the top of my Game.PHP file, I've included this in the <head> portion of the HTML... and I've added the specified default_charset to my php.ini file, and the AddDefaultCharset to my Apache file. What am I doing wrong?
You should be able to use the PHP utf8_encode() function. Try $character = utf8_encode(put your character here) and be sure to use single or double quotes around the character.
In NotePAD++
Settings -> Preferences -> New Document/ Open Save Directory
Under New Document Encoding -> check UTF8 without BOM
Related
This may be a stupid question but its not a matter of what I can find, its a matter that I dont know what to search for. There are some special characters that don't show correctly in php. I'm taking some information from an xml file, and echo-ing them.
ie:
should be -> Nürnberg
echoes as -> Nürnberg
any tips on what to look for, or how to resolve this?
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
You simply have an encoding mismatch. Get up to speed with these articles:
What Every Programmer Absolutely, Positively Needs To Know About Encodings And Character Sets To Work With Text
Handling Unicode Front To Back In A Web App
try a different character set on the page you're echoing from
http://www.w3schools.com/tags/ref_charactersets.asp
Can you try with following meta tag in your HTML head.
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
There is a mismatch between the character encoding of your XML and what you are outputting from PHP. Most likely, one is UTF-8 and one is ISO-8859.
On the PHP side, you can set this with a header directive
<?php
header('Content-Type: text/plain; charset=ISO-8859-1');
header('Content-Type: text/plain; charset=utf-8');
?>
and/or in the outputted HTML
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
On the XML side, most quality text editors allow you to specify the character encoding as you save the file. (E.g. WordWrangler on Mac)
If the XML file is indeed in ISO-8859, you could use utf8_encode() to convert it to UTF-8 as you read it in.
An in-depth discussion of PHP and character encoding.
"I'm taking some information from an xml file, and echo-ing them."
Windows command line doesn't support utf8 properly as it doesn't use an UTF8 font.
Just put the file into somewhere that's reachable through a web server and test it by calling the file through the web server.
Alternatively pipe the output of the script into a text file:
php test.php > output.txt
And either open output.txt is a UTF8 capable editor or use a utf8 capable 'Tail' program.
Test.php
<?php
echo "Nürnberg";
?>
Running from command prompt:
php test.php
Nürnberg
Calling through a web server http://localhost/test.php
Nürnberg
I'm including a menubar through php include and for some reason the menubar doesn't display UTF-8 special characters.
The rest of the page works fine, just not the left navigation.
What could be the reason? I tried adding:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
on the included file too but I still can't get the caracters.
I'm testing it here:
http://www.lilianasanmiguel.com.ar/acol1.php
Make sure that you actually save the files in UTF-8 encoding in your editor.
Check if the file you include is uft-8 encoded. In Eclipse you can do so by right-clicking in the file an check under "Properties"
Be aware that the standard PHP string functions won't work with UTF-8 - they all assume a fixed with character set. Check your code and make sure you're using the mb_* equivalents instead.
I'm having a weird problem regarding PHP and charset encoding..
I am developing a PHP Page that outputs some latin (ã, á, à, and so on) characters.
When I run the page from my localhost, it works just fine. However, when I upload it to my test-server and access it via a url, then all latin characters become little squares (in IE by the way).
I've changed the character encoding on my browser back and forth to utf8, western european and so on, but none seem to work
Does anybody have an idea?
Either set the default_charset in php.ini to UTF-8, or if you don't have the control over this, add the following line to the top of the PHP file, before you emit any character to the response body:
header('Content-Type: text/html;charset=UTF-8');
See also:
PHP UTF-8 cheatsheet
Have you checked for different default_charset settings in the php.ini files of your localhost and your test server?
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> // Or actual encoding
</head>
i am working on php. in my index.php page i have included right.php. right.php contains greek text. index.php has the html headers. the greek text are not showing correctly. when i open the right.php file in dreamweaver and save the page, it gives warning about the text. what can i do to solve this? because right.php has common contents which is used in many pages.
This is all to do with the content type of your pages. Most likely you are trying to save / display the text in latin1 format which doesn't support the characters you are trying to display.
The most sensible thing to do is convert everything to UTF-8. If you're manually editing the text then ensure your text editor (i.e. Dreamweaver) is set to save the files as UTF-8 and then ensure you have the following meta tag on your page
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
Make sure you are saving your files as UTF-8 encoding (check preferences in DreamWeaver to find file encoding). Also make sure your HTML <head> tags include charset similar to this: <META http-equiv="Content-Type" content="text/html; charset=UTF-8">
You can use a different character set if you prefer, but UTF-8 supports the entire Unicode character space, so it's pretty safe.
You have to set file encoding to utf-8 and set it also in <meta> charset tag in <head> HTML.
I keep getting these weird text characters when I display user submitted text. like in the following example below. Is there a way I can fox this using PHP, CSS or something so that the characters are displayed properly?
Here is the problem text.
Problems of �real fonts� on the web. The one line summary:
different browsers and different platforms do �hinting�
Here is my meta tag.
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
It's an encoding problem. Make sure you send the correct encoding to the browser. If it's UTF-8, you'll do it like this:
header("Content-type: text/html; charset=utf-8");
Also, make sure that you store the content using the same encoding throughout the entire system. Set your database tables to utf8. If you're using MySQL, run the SET NAMES utf8 query when connecting to make sure you're running in UTF-8.
These weird characters occur when you suddenly switch encoding.
Also, some functions in PHP take a $charset parameter (e.g. htmlentities()). Make sure you pass the correct charset to that one as well.
To make sure that PHP handles your charset correctly in all cases, you can set the default_charset to utf-8 (either in php.ini or using ini_set()).
Set your page to UTF-8 encoding.
Please check with the char-set in header section.
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
use this below one:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
or try this one:
htmlentities($str, ENT_QUOTES);
Could be problem with file encoding please check that your files is correctly encoded, saved as "UTF-8 without boom", also if you are saving to database use SET NAMES UTF-8