I got problem with some special characters. I have defined the meta tag as
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
so far so good. But in one occassion I have a select tag with many options with many special characters. I got problem showing (å ä ö). They are defined in .js file and are appended to the document using DOM. Pls. are there any solution except using &... forgot the name for that type.
Second character problem I have is in php. I try to send an email with Amazon SES.
<?php
$message['Body.Html.Data'] = "Please Confirm that you are a Tönt by clicking on this link"." ....<a href='s'>Tönt</a>";
$message['Body.Html.Charset'] = 'utf-8';
?>
the ö is not showing properly?
You'd better use:
<?php header('Content-type: text/html; charset=utf-8'); ?>
At the very top of your PHP file, no need to use http-equiv metas when you can send some real http headers ;-)
Also check if your files (both PHP and JS) are encoded in UTF8 in your editor.
Setting an UTF8 header on non UTF8 files will produce strange results for sure!
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.
How do I interpret some characters into their proper form in PHP?
For example, the string is \u00c9rwin but PHP print it as Érwin, and the correct form must be Érwin
What is the proper PHP code for this? I am pretty sure this is not an HTML entity, or is it?
P.S. no encoding was declared on the PHP file
Look into utf8_encode and utf8_decode.
It's important as well to go UTF8 across the whole stack. What that means is that your database connection should be using UTF8 (here's how in MySQL), your HTTP Content-Type should be returning UTF8 (see mgraph's example below) and you should also be setting it in the meta tag so that there is no need to encode/decode at all as you're using the same charset everywhere.
add this in header:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
or:
<?php header ('Content-type: text/html; charset=utf-8'); ?>
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.
When I try and execute this code to print out an Arabic string: print("إضافة"); I get this output: إضاÙØ©. If I utf8_decode() it I'll get ?????. I have "AddLanguage ar" in my apache configuration but it doesn't help. How do i print out this Arabic string?
Also set your page language to utf8 eg:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
and then see it if worked. If that still doesn't work, go and check this out, it is complete solution for the arabic language using PHP:
http://www.ar-php.org/en_index_php_arabic.html
You may want to check out this too:
http://www.phpclasses.org/browse/package/2875.html
It might be necessary to indicate to the browser which charset you are using -- I'm guessing it's UTF-8.
IN order to achive that, you might try putting this portion of code at the beginning of your script, before any output is generated :
header('Content-type: text/html; charset=UTF-8');
[utf8_decode][1] will try to decode your string from UTF-8 to latin1, which is not suited for Arabic characters -- hence the '?' characters.
You may want to set
default_charset = "utf-8"
in your php.ini. Default charset directive instructs the server to produce correct content type header.
You can also do it in runtime:
ini_set('default_charset', 'utf-8');
You may also want to check your browser font if it has Arabic support. Stick to common fonts like Arial Unicode and Times New Roman.
Well,
First: Add by the beginning of HTML page
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
second:
if you are using AJAX encode data using encodeURIComponent
Third:
First line of your PHP page should be
header('Content-Type: text/html; charset=utf-8');
and decode the data sent to PHP using urldecode
Regards,
I have an php page with mixed Latin and Arabic characters. The charset declaration tag is in the html code
and the file is saved as UTF-8. All the text is static and in the php file (does not come from a DB or an external source)
When I browse to the site some pages randomly get corrupt in IE and FF and display all question marks. After I refresh the page, text is displayed properly though... I have been working with Arabic and Hebrew for a long time and this is the first time I run in to this issue. Can anybody think of a cause?
Chrome is always fine...
Turns out the script reference that was before the meta description was causing the problem. I moved
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
to be the first item after the opening head tag and this is no longer an issue. Thanks for all the comments..
P.S I wasn't the one who code this page, and only working on localizing it, thats why I didn't even think that meta tag being after script would even make a difference...
Try to send appropriate header, something like this:
header("Content-Type: text/xml; charset=utf-8");
Try using UTF8_encode on your content:
http://php.net/manual/en/function.utf8-encode.php
If you have some text you want to store in a DB and display even if the page encoding is latin-1, there is a free tool that can convert Unicode to escaped HTML:
http://www.sprawk.com/tools/escapeUnicode