2

I am having problem in displaying the   in my web page, after using utf8_decode() in PHP it gets displayed as �.

i have been using

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

I just noticed, all the other special characters, like ® , ™ etc are also not working.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Chetan Sharma
  • 2,539
  • 5
  • 25
  • 41
  • If it is urgent, you should provide as much info as possible: we need the source code and ideally the output of the script on your web server to be able to help you in the best way. – soulmerge Oct 22 '09 at 19:45
  • I have noticed that there is a blank line at the beginning of code, can that cause problem ? – Chetan Sharma Oct 22 '09 at 20:18
  • Are you really using the character reference ` `? – Gumbo Oct 22 '09 at 20:56

5 Answers5

5

Be sure that you've specified UTF-8 encoding in your HTML document's tag:

  <meta content="text/html; charset=UTF-8" http-equiv="content-type" />
RyanTheDev
  • 601
  • 1
  • 5
  • 11
1

That's strange since utf8_encode('&nbsp;')==='&nbsp;'. Regardless of whether it's utf8 or latin1 encoded the byte-sequence for &nbsp; is the same.
Is the remaining string properly utf8 encoded?

edit: Why do you use utf8_decode() (converting utf8 encoded strings to latin1) in the first place when you're telling the browser that your page is utf8 encoded?

VolkerK
  • 95,432
  • 20
  • 163
  • 226
  • I don't know that the string is properly utf8 encoded or not, how can i check it ? – Chetan Sharma Oct 22 '09 at 20:19
  • If the mbstring moule is enabled you can use mb_check_encoding() to check the encoding. http://docs.php.net/mb_check_encoding But please note my edit. – VolkerK Oct 22 '09 at 21:08
1

Have you checked the encoding of the php file itself?

In some windows editors (like notepad++) you can have some utf-8 character problems when you check the wrong encoding for your file - even if you set your meta tag correctly.

In notepad++ you can change it in this section:

Change notepad++ file encoding http://img198.imageshack.us/img198/9081/notepadp.png

If you're not using notepad++, we'll need some more detailed information from your setup, like Operating System used, IDE, etc.

GmonC
  • 10,924
  • 1
  • 30
  • 38
0

Also make sure you give the document a proper dtd definition by putting something like this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

As the first line of html in your php file.

John Scipione
  • 2,360
  • 4
  • 25
  • 28
  • even this didn't help, i just changed it, i have noticed that there is a blank line at the beginning of code, can that cause problem ? – Chetan Sharma Oct 22 '09 at 20:17
0

When you use utf8_decode, the string that is passed to this function where is it loaded from? Are you loading data from database? Do you have any included files? If so, check that they are all encoded as GmonC wrote. Try to echo &nbsp; somewhere in page and see if it will show correctly. If not, try to make clean .php file and than see if problem still occurs. If not than some included file could be the problem because it could have different encoding

ilija veselica
  • 9,414
  • 39
  • 93
  • 147