I have been trying to display my text in PHP but I am getting issue from Turkish characters it display it as ıııööö
I am reading data from MySQL but the issue is from the PHP. Please what it is missing?
My code is simple:
<?php
echo "ş i ü ğ";
?>
Check, if your website is in UTF-8.
Just copy following code to the <header> tag of your documment:
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
Or you can use just shorter version according to HTML5. Compatibility is fine:
<meta charset='utf-8'>
See difference between this two metatags: <meta charset="utf-8"> vs <meta http-equiv="Content-Type">
Or you can use header. This code place into your PHP code. The best position is at the start of the document.
header('Content-Type: text/html; charset=utf-8');
Or check if your file is in UTF-8. This you can do with your code editor. I use PSPad and i recommend it to try.
In addition to meta headers, the file's own character encoding is also important. I had suffered from the same issue with the files generated with notepad++ and notepad back in Windows, then I saved the file as UTF-8 and it all solved it.
E.g: with Sublime Text; file/save with encoding/UTF-8.
Related
I use PHP to access a database to get a string like this
‘Chloe’ Fashion Show & Dinner
and then I do a printf() to output the string as html, but my webpage shows this:
�Chloe� Fashion Show & Dinner
All contents are English-based, do I miss something in PHP?
Where should I be checking?
Check if your .php file is encoded as UTF-8 without BOM
Check that your connection to the database is UTF-8
Check that you send <meta charset="utf-8"> in your HTML markup in the <head> tag
If your connection to the database is not UTF-8 and you don't want to change it (but I recommend it -> everything UTF-8 is the most secure solution against character rubbish) use utf8_encode($databaseValue) to ensure the encoding of your value is UTF-8.
Make sure that you use:
<meta charset="utf-8">
in the head of your page.
You need to add charset meta tag in 'head' section of html.
Note that the meta tag must appear within the first 1024 bytes of rendered page.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
I am having a strange issue. I have Swedish characters. My charset works fine when in loop and being pulled from mysql using PHP but when I simply enter HTML text Swedish character Å, Ä and Ö it does not work. Currently this is my set Charset:
<meta http-equiv="content-type" content="text/html" charset="ISO-8859-1">
Here is a picture of how it looks in the browser:
Now here is a picture of data being pulled from Mysql (in loop) on the same page:
If this question has been asked before, please direct me to the page. Could it be somethign to do with the actual page encoding?
You should try this:
<meta http-equiv="content-type" content="text/html" charset="UTF-8">
Probably the file itself ist stored in UTF-8.Try and save it as a ANSI file.
In notepad++ this can be done via Encoding > Encode in ANSI in the menubar.
Or try to change the meta tag as already suggested.
OK so I have a PHP file with several strings of text in various languages. For most languages like French or Spanish I just simply type in the characters.
The problem I have is with Russian language characters. The PHP file is encoded in UTF-8, how can I make sure that the Russian characters are both saved correctly and displayed correctly on the output web page... Is it just a case of pasting the text into the PHP file, or is there a way to guarantee the characters will be saved into the file correctly - perhaps converting it into HTML-like notation for example?
Obviously I am assuming the end user will have the correct encoding set in their web browser, I just want to make sure I got it all covered from my end.
I am using Notepad++ on Windows to edit my PHP file.
Thanks!
If you want to tell browsers your encoding, place it inside your <header> tag:
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
Or short version
<meta charset='utf-8'>
That should be pretty enough for Russian characters to be correctly displayed on a webpage.
if your doctype is html declare <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'> but if your doctype is xhtml then declare <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />.Never assume that end-user will act correctly during your designsIf you already have some document, edit your document's meta tag for charset declaration and use notepad++ encoding>convert to UTF-8 without BOM, save your document, safely go on with your multilingual structure from now on.php tag is irrelevant for your question since you don't mention about any database char setting.
There is no difference between Latin and Cyrillic characters in UTF-8. Both are just byte sequences. Configure your server or PHP script to send Content-Type: text/html;charset=utf, and you are rather safe.
Your editor might have problems when the font you are using does not contain Russian characters. Choose another font then.
And please ignore the <meta> element recommendations. You don't need that: it is useless when your HTTP headers are correct, and maybe harmful if they aren’t.
Well you have to check 2 things
To ensure that *.php is an UTF-8 file I use PSPad. If file is not in UTF-8, I save
it like that: http://stepolabs.com/upload/utf-8.png
Then your website must have UTF-8 encoding in <meta> tag;
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
... more about metatagging.
Finally if everything is done well - (format and meta declaration) all should be displayed properly!
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 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.