’ is being displayed instead of - in php page
I tried using different encoding types like:
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
and
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
but result is the same. What could be the problem?
Input
<strong style="color:#A8A8A8;">1</strong> – Lorem Ipsum.
Result
1 – Lorem Ipsum.
Make sure your html header specifies utf8
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
That usually does the trick for me (obviously if the content IS utf8).
You don't need to convert to html entities if you set the content-type.
check http://php.net/manual/en/function.mb-convert-encoding.php
<?php
header('Content-Type: text/html; charset=utf-8');
mb_internal_encoding('utf-8');
?>
may be this will help you.
It looks like your source data is converted from one to another encoding along the way. Try to make sure ALL steps have the same encoding.
Is your (MySQL?) data stored as UTF8?
Is your .php file saved as UTF8?
Conversion errors like this usually pop up when handling UTF8 data as ISO-8859-1 data. (multibyte vs singlebyte? not sure).
The fact that the meta tag doesn't change the output is a strong indicator that there's something overriding it; probably it's the charset specified in the HTTP header (which has precedence over the meta tag), are you sure you're not setting it there?
Your document is most likely encoded in UTF-8 since – is the iso-8859-1 presentation of the UTF-8 encoded character –.
What you need is the meta-tag you describe:
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
Since it isn't working, the tag might to be ignored. Suggestion is to use the browser and check what encoding it tries to use (Tools - Encoding in Chrome).
If the browser uses UTF-8, you have double-encoded the characters. Check your code if so that you don't have an excessive utf8_encode(...)
If the browser uses Latin1 (iso-8859-1) your tag is ignored or overridden by the HTTP header. Try to validate your HTML with an online validator. Check the sent header information with your browser's development tool to make sure iso-8859-1 is not set as encoding.
Had the same problem when creating a file from javacode and setting the encoding to UTF-16 did the trick.
Related
I have a problem of special character writing on my website coded in PHP (data from database and normal writing html)
Code :
code in Sublime text
Result :
result in web
I have in my header :
‹meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"›
It's important that your entire line code has the same charset to avoid issues where characters displays incorrectly.
There are quite a few settings that needs to be properly defined and I'd strongly recommend UTF-8, as this has most letters you would need (Scandinavian, Greek, Arabic).
Here's a little list of things that has to be set to a specific charset.
Headers
Setting the charset in both HTML and PHP headers to UTF-8
PHP: header('Content-Type: text/html; charset=utf-8');
(PHP headers has to be placed before any kind output (echo, whitespace, HTML))
HTML: <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
(HTML-headers are placed within the <head> / </head> tag)
File-encoding
It might also be needed for the file itself to be UTF-8 encoded. If you're using Notepad++ to write your code, this can be done in the "Format" drop-down on the taskbar. You should use UTF-8 w/o BOM (see this SO).
Other
Some specific functions have the attribute of a specific charset, and if you are using such functions, it should be specified there as well. Read the documentation for each function.
Should you follow all of the pointers above, chances are your problem will be solved. If not, you can take a look at this StackOverflow post: UTF-8 all the way through.
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
in PhpMyAdmin it shows up as 'Petite-Réserve" but when i echo it to a webpage it shows as "Petite-R�serve" MyISAM latin1_swedish_ci is the database encoding and <!DOCTYPE html><head><meta http-equiv="content-type" content="text/html; charset=utf-8" /> is at the top of the page. Not sure how to fix this. I'm allowing users to input text and users are French and English. I'm using Google Chrome and it shows up as a question mark in a triangle. Any ideas?
You need to use the right content-type on the page - since you are outputting latin1 (as defined in your database), try this:
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
iso-8859-1 is the encoding name for latin1.
If you use a different encoding to output data to that is has been saved in, you have to encode or decode the data beforehand. Try
utf8_encode($value);
in this case.
Alternatively, change the encoding of your HTML to iso-8859-1.
Often best to decide on one charset and not to mix them. If you mix them you will have to convert between them. mbstring can help there. Best to switch your database to UTF-8. It is more flexible then the latin variations.
Check the HTTP response headers sent by your webserver. One of the headers might include the content-type, and that value in your http headers might not match the UTF-8 encoding declaration you've got in 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