tags:

views:

361

answers:

6

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

i have been using

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<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 charactes, like ® , ™ etc are also not working.

A: 

What is the output from your PHP, and what is the code you're using to output the content? Are you using a proper doctype/encoding in the actual HTML?

BraedenP
+2  A: 

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
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" />
Chetan sharma
+1  A: 

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
I don't know that the string is properly utf8 encoded or not, how can i check it ?
Chetan sharma
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
A: 

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
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
A: 
GmonC
A: 

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

ile