Text encoding

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rix501
Forum Newbie
Posts: 3
Joined: Mon Dec 28, 2009 8:51 pm

Text encoding

Post by rix501 »

I have an html page with special characters like "é" and "ñ" and they get displayed fine, but if I switch the extension to php, weird diamond question marks appear. I've done everything that I know of, I've set the charset to utf-8 everywhere, but still nothing works.

Any ideas?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Text encoding

Post by requinix »

And what is included in "everywhere"? It's pretty much (a) a call to PHP's header() function, or (b) a <meta> in the HTML page's <head>.
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

Re: Text encoding

Post by Apollo »

How did you include those characters in your php file? Did you(r editor) save it with utf-8 encoding?

Instead of including é and ñ literally, you're probably better off by using their html-entity equivalents: &eacute; &ntilde;
rix501
Forum Newbie
Posts: 3
Joined: Mon Dec 28, 2009 8:51 pm

Re: Text encoding

Post by rix501 »

I saved it in th php.ini file, in the head (meta) and even in apache.

I don't know how the editor saved the file. Is that the problem?
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

Re: Text encoding

Post by Apollo »

rix501 wrote:I don't know how the editor saved the file. Is that the problem?
Yes. In your headers you say you are outputting UTF-8, but what you're actually outputting is whatever encoding your editor happens to use (cause that's what's saved in the .php file, so that's what PHP outputs).

There are all kinds of solutions to that, but simply using &eacute; and &ntilde; and the likes is probably the best way to go.
rix501
Forum Newbie
Posts: 3
Joined: Mon Dec 28, 2009 8:51 pm

Re: Text encoding

Post by rix501 »

Just checked it out and it was definitely the text editor saving the file in another encoding.

Thanks for the help!
Post Reply