9

I'm developing a website using PHP and these strange chars "" appears in my page, right on the top of it. My code is this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><?php echo '';?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

But when I see the source code in the browser, it shows this:

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

I don't know if has any relation to the encoding I'm using, because when I change the charset to charset=utf-8 it disappears but I must use iso-8859-1

Cœur
  • 37,241
  • 25
  • 195
  • 267
rlc
  • 5,809
  • 5
  • 38
  • 46
  • Why must you use `iso-8859-1`? – SLaks Jul 14 '10 at 01:39
  • I don't know if I must. I started to use it because some chars as "á", "é" appear as �. It's a website in portuguese (PT-Br) – rlc Jul 14 '10 at 01:45
  • 3
    If you have no good reason to use ISO-8859-1, don't. Save yourself a lot of headaches and just use UTF-8 for everything. Unicode (UTF-8) can encode virtually any possible character on this planet, all other encodings can only encode a limited subset, so you need to make sure you're never using characters outside that subset. You'd need a really good reason to limit yourself like that. – deceze Jul 14 '10 at 01:48
  • OK. Gonna try to use UTF-8. But what about those annoying � ? What should I do so they are gone? – rlc Jul 14 '10 at 01:50
  • [The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)](http://www.joelonsoftware.com/articles/Unicode.html) :) – deceze Jul 14 '10 at 01:51
  • 1
    Also, something I wrote just yesterday: http://stackoverflow.com/questions/3233743/php-mysql-html-javascript-i18n-headache/ – deceze Jul 14 '10 at 01:52
  • How to solve this with powershell: may be it helps someone: Powershell: Get-ChildItem -Recurse -Include "*.phtml" | foreach-object { $MyFile = Get-Content $_.Fullname $Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding($False) [System.IO.File]::WriteAllLines($_.Fullname, $MyFile, $Utf8NoBomEncoding) } – Crisboot Nov 27 '12 at 00:00
  • Does this answer your question? [Write text files without Byte Order Mark (BOM)?](https://stackoverflow.com/questions/2437666/write-text-files-without-byte-order-mark-bom) – Karl Knechtel Jan 11 '23 at 04:23

4 Answers4

18

That's a BOM character, which is there because the source code files are saved as UTF-8 BOM. Try to save them as UTF-8 no-BOM (or whatever your editor calls it) or indeed ISO-8859-1 if you must use it (...why would you?).

deceze
  • 510,633
  • 85
  • 743
  • 889
  • 1
    It depends on the editor you're using. So... what editor are you using? – clee Jul 14 '10 at 01:41
  • @Rafael Sorry, I can't tell you how to do that in Eclipse. Look at the documentation how to set a files encoding. – deceze Jul 14 '10 at 01:50
  • Oh man. You've saved my life with that. Saving the file as an ANSI one solved my problem. – Laszlo T Feb 20 '12 at 10:01
3

If you want to use iso-8859-1, you need to save your PHP file as iso-8859-1.
For detailed instructions, please tell us which editor you're using.

However, I highly recommend that you use UTF8 instead.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
0

Look at the "Page Info" screen and see what character set the browser thinks you're in. The odds are that your web server is forcing UTF-8 with its Content-Type header, which trumps the meta tag.

zwol
  • 135,547
  • 38
  • 252
  • 361
-1

simple solution, just placed your html/php code is start from first line, I am just do that to resolve these problem, and it's work.

ndang
  • 1
  • Don't you think that OP _did_ place the code right? Why didn't you check the answer that was _accepted_ (as it - obviously - described the problem and its possible solution quite correctly)? – raina77ow Oct 26 '12 at 12:53