UTF8 displays triangles for special chars

Discussion forum for MOD Writers regarding MOD Development.
Locked
iankent
Registered User
Posts: 27
Joined: Thu Jun 25, 2009 3:28 pm

UTF8 displays triangles for special chars

Post by iankent » Mon Nov 16, 2009 3:29 pm

Hi

This problem is similar to one I had recently, but the other way around (see http://www.phpbb.com/community/viewtopi ... &t=1846245).

In this case I'm trying to pull some of the latest post text from phpbb_posts table, but when displaying them apostrophe's are displayed as a � (other special characters are also a problem, e.g. a £). The text is definately stored correctly in the database table as viewtopic.php is dislaying it correctly, just not my code.

The page, database and browser are all handling the text as UTF8 (as far as I can see anyway), and as it works fine on viewtopic I'm stuggling to see what the problem is.At the moment I'm just retrieving the text from the database and using generate_text_for_display with the entries bbcode_uid and bbcode_bitfield, but I've tried using code from viewtopic instead of my own and have the same problem :( just can't see what viewtopic is doing that I'm not!

edit: if I force the browser to use different encoding, instead of a � for apostrophe I get:
iso-8859-1: ¿½
iso-8859-15: ¿œ
windows-1252: �

Any suggestions?

Thanks

User avatar
ameeck
Former Team Member
Posts: 6559
Joined: Mon Mar 21, 2005 6:57 pm

Re: UTF8 displays triangles for special chars

Post by ameeck » Mon Nov 16, 2009 5:32 pm

Are you trying to pull the data with some custom script of yours? Are you using the phpBB database functions? Would you have a link?

iankent
Registered User
Posts: 27
Joined: Thu Jun 25, 2009 3:28 pm

Re: UTF8 displays triangles for special chars

Post by iankent » Mon Nov 16, 2009 5:45 pm

The data is coming from a stupidly complex query that pulls info from 15 separate tables using unions to merge the results into a single result, e.g.

select a,b,c,'phpbb' as source from phpbb_posts
union select a,b,c,'xyz' as source from another_table
union select a,b,c,'zyx' as source from table_xyz

the result is then processed and if the source is phpbb I'm applying generate_text_for_display, but nothing else is done to it as yet - I'm assuming I'm missing something?

If you need to see it I can send you a link and username/password by PM as its a private forum

not sure if it makes a difference but in this particular case, the uid and bitfield are being merged in the sql query using concat then split later using explode. I don't think thats causing a problem as the bbcode is being parsed correctly, and another page that has the same problem pulls the bitfield and uid directly.

I've tried looking through viewtopic and can't see any extra steps over what I'm doing, but obviously there is :)

User avatar
ameeck
Former Team Member
Posts: 6559
Joined: Mon Mar 21, 2005 6:57 pm

Re: UTF8 displays triangles for special chars

Post by ameeck » Mon Nov 16, 2009 6:05 pm

Have you tried overriding the default db collation in a SQL query before running the query?

Code: Select all

SET NAMES utf8;

iankent
Registered User
Posts: 27
Joined: Thu Jun 25, 2009 3:28 pm

Re: UTF8 displays triangles for special chars

Post by iankent » Mon Nov 16, 2009 6:40 pm

Fixed, yeyyyyyy! Thank you!!! Can't believe it was that simple! Explains why I hadn't noticed elsewhere though, had always used the phpbb db connection! *doh*

Locked

Return to “[3.0.x] MOD Writers Discussion”