Sunday, October 15, 2006

Odd characters in PHP server output

Switched from php4 to php5.

First problem: strange control characters that the browser renders as black diamonds with a question mark inside. Like this: ��

So I saved the html file.

Looked at it with vim -b.

The confused black diamonds were "a0" in hex.

I typed "a0" into Google.

Others had this problem, with perl. It was a matter of content-type character sets (charset): is0-8859-1 vs. UTF-8 ...

Looked at the HTML output of another server I had (with php4) for phpinfo(). Compared side-by-side with the php5 output. Very useful ... a bunch of sections with settings in tables. It was in a section entitled "HTTP Headers Information", subheading "HTTP Response Headers". The good server had the name/value pair:

Content-Type text/html; charset=iso-8859-1

... the bad, problem server had:

Content-Type text/html; charset=UTF-8

So, I looked at the /etc/php5/apache2/php.ini file.

there's a line that read:

;default_charset = "iso-8859-1"

I tried removing the leading semi-colon (uncommenting). Typed:

/etc/init.d/apache2/restart

And that fixed it. The diamonds disappeared.

No comments: