I moved my website from my local test server to NameCheap shared hosting and now I'm running into a problem - some of the pages aren't displaying utf-8 special characters properly (showing question marks instead). All pages are utf-8 encoded, as are all database tables. The strange thing is, some pages display correctly and some don't, in a seemingly random pattern.
For instance, my index page is fine, but my profile page isn't. faq.html works fine, but when I rename it to faq.php it doesn't. And weirdest of all, I have a page with two JQuery tabs where one displays correctly and the other doesn't!
Can someone help me out with this?
When you want to insert a special character, select Insert > HTML > Special Characters. From there are you presented with a few of the most common, or you can choose “Other” to view all the characters available. Simply select the character you would like to insert and the code is inserted for you.
You can enter any Unicode character in an HTML file by taking its decimal numeric character reference and adding an ampersand and a hash at the front and a semi-colon at the end, for example — should display as an em dash (—).
The HTML5 Standard: Unicode UTF-8 The Unicode Standard covers (almost) all the characters, punctuations, and symbols in the world. Unicode enables processing, storage, and transport of text independent of platform and language. The default character encoding in HTML-5 is UTF-8.
click(function(){ var fn = $("#folderName"). val(); var regex = /^[0-9a-zA-Z\_]+$/ alert(regex. test(fn)); }); }); This return false for special chars and spaces and return true for underscore, digits and alphabets.
This is really annoying problem to fix but you can try these.
First of all, make sure the file is actually saved in UTF-8 format.
Then check that you have <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
in your HTML header.
You can also try calling header('Content-Type: text/html; charset=utf-8');
at the beginning of your PHP script or adding AddDefaultCharset UTF-8
to your .htaccess file.
It sounds like that if you request faq.html
the webserver signals your browser that the file is in UTF-8 encoding.
Check that with your browser which encoding is announced and used, please see the documentation of your browser how to do that. Every browser has this, most often accessible via the menu (to specify your preference which website's encoding should be used) and to see what the server returned, you often find this in page properties.
Then it sounds like that if you request faq.php
the webserver singals your browser that the file is in some other encoding. Probably no charset/encoding is given as per default PHP configuration setting. As it's a PHP file you can most often solve this by changing the PHP configuration default_charset
Docs directive:
default_charset = "UTF-8"
Locate your php.ini on the host and edit it accordingly.
If you don't have the php.ini available, you can change this by code as well by using the ini_set
Docs function:
ini_set('default_charset', 'UTF-8');
Take care that you change this very early in your script because PHP needs to be able to send out headers to have this working, and headers can't be set any longer if they have already been send.
Manually sending the Content-Type
header-line does work, too:
header('Content-Type: text/html; charset=UTF-8');
Additionally it's good practice that all the HTML pages you output have this header as well in their HTML <head>
section:
<html> <head> ... <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> ...
Hope this is helpful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With