-5

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"›
    
hatane
  • 36
  • 6
  • [`htmlspecialchars`](http://php.net/manual/en/function.htmlspecialchars.php)? – Can O' Spam Feb 10 '16 at 15:44
  • You will have to encode characters correctly (for example, e with accent can become `&eegu;` - or maybe set your encoding to unicode. – somethinghere Feb 10 '16 at 15:45
  • Why the downvotes? I'm assuming because the question doesn't simply display the code and simply display the image for the fail? So @hatane should edit his question and learn how to use the code tags as well as upload an image correctly so it shows up to us, the reader? – zipzit Feb 10 '16 at 15:48
  • @zipzit i need 10 reputation to post image , it's ok for you – hatane Feb 10 '16 at 16:50

1 Answers1

2

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.

Community
  • 1
  • 1
Qirel
  • 25,449
  • 7
  • 45
  • 62
  • thanks for your response it's resolved i have to add : header("Content-type: text/html; charset=UTF-8"); – hatane Feb 10 '16 at 16:16