Jump to content

Can PHP versions affect character handling?


wilsonf1

Recommended Posts

I have 2 identical copies of a CMS I designed in PHP.It's been running from a Windows server, trouble free for years.I uploaded it to an Apache server, then noticed when I save £ symbols to the database, although I see £ in the SQL statement, £ is being saved to the field.My webpages are outputting a diamond before the pound symbol in firefox meaning it's buggered.I have tested my original CMS install on the Windows server by pointing it at the same database as the new system, and all is fine with £ symbols.So based on the code of the CMS being identical, and sharing the same database table - the only other factor is the server is different.Can anyone explain what could be happening or anyway to stop it from happening?MASSIVELY appreciate anyones help :)

Link to comment
Share on other sites

Hey wilson,That sounds weird. Have you remembered to set the connection character set/collation in your script/server?
Well that's the thing, in my original setup on windows I spent so many hours trying to get characters working and saving correctly I originally settled on using iso-8859-1So my CMS page header sets iso-8859-1, my actual web pages use iso-8859-1 as well. I've never had any luck with utf8!I have these 2 lines commented out in my connect function: //mysql_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'", $this->connection); //mysql_query("SET character_set_results = 'iso-8859-1', character_set_client = 'iso-8859-1', character_set_connection = 'iso-8859-1', character_set_database = 'iso-8859-1', character_set_server = 'iso-8859-1'", $this->connection);Yet characters work perfectly well on that server?
Link to comment
Share on other sites

Add a content-type header to your pages using the header() function.Example:

header("Content-Type: iso-8859-1");

And you probably have to set the database connection charset aswell.

Link to comment
Share on other sites

Add a content-type header to your pages using the header() function.Example:
header("Content-Type: iso-8859-1");

And you probably have to set the database connection charset aswell.

omg.... it worked!!!! just setting the header line! This is perfect, thanks so much, HUGE weight off my shoulders. I know it's something simple but still, I can tell my content team the problem has gone and their data won't mess up after they save.Big big thanks for looking at this today.
Link to comment
Share on other sites

glad to be of assistance
Ok one thing i've noticed since putting that in, is when I'm debugging half way through a function, inside a class, I can't echo anything out, as soon as i put echo "hi!"; in a class, the page tries to "download" in firefox, like is says "where do u want to save index.php?"when i comment out // header("Content-Type: iso-8859-1"); which is in an include at the VERY top of any code on the page, my echo works?
Link to comment
Share on other sites

That's not the correct way to specify a character encoding, a character encoding is not a content type. The content type needs to be text/html if you want the browser to display it, and you can specify the character set in the same header:http://www.w3.org/International/O-charset
Hey man... I use <meta http-equiv="content-type" content="text/html;charset=iso-8859-1" /> on every single webpage i create, it is used in my CMS, as well as my front end - but I was still getting screw ups.The fix did work though that he said
Link to comment
Share on other sites

The first example on that page shows how to specify both the content type and character encoding in the content-type header. The example posted bu chokk just specifies the character encoding in the content-type header, and that is not what the content-type header is for. The character encoding is an extra part of the content-type header, but it is not a content type itself. The content type needs to be text/html in the header you send, but you can also specify the ISO encoding you want to use. It's similar to the meta tag, but it's sent from the server as a header. That is why the browser is downloading the page, because it sees a content type from the server that it doesn't understand. It doesn't understand a character encoding as a content type.

Link to comment
Share on other sites

  • 1 month later...
glad to be of assistance
Hey man - I know this was one month ago, but only just realised that using header("Content-Type: iso-8859-1"); - IE asks to download my webpage rather than display it!Any work around? FF is fine!
Link to comment
Share on other sites

Sorry guys, may have just been as simple as changing it to:header("Content-Type: text/html;iso-8859-1");
header("Content-Type: text/html;charset=iso-8859-1");

the link which has justsomeguy provided holds more info on it

Link to comment
Share on other sites

I'm glad you got it worked out, that's what I was talking about in post 8, where I linked to the documentation about the content-type header that it doesn't seem like you read. The first example on that page is exactly what you were trying to do.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...