cparekh Posted April 25, 2008 Share Posted April 25, 2008 Hi, I'm pulling data from a DB and some of this contains the € symbol which displays as a '?' - what can I use to display this symbol properly? I've tried htmlspecialchars() and htmlentities() but no go! Possibly on a related note, some of the info in the db contains MS characters like 'smart tags' for single and double quotes. These also display as '?' marks. Is there a way to have php display these properly? Thanx in advance. C. Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted April 25, 2008 Share Posted April 25, 2008 you should convert special characters when putting them into your database and also make sure your database supports the correct character encoding (I always enable utf-8 for my database). Quote Link to comment Share on other sites More sharing options...
conker87 Posted April 25, 2008 Share Posted April 25, 2008 As with the smart tags, I just get rid of them. I was about to get the code I use and paste it here, but then I remembered it's not on my MP3 player anymore. I'll try and get it when I get home. Quote Link to comment Share on other sites More sharing options...
cparekh Posted April 25, 2008 Author Share Posted April 25, 2008 Hi, unfortunately the db is in use for a CRM (GoldMine, which uses a MSSQL db) and so a lot of the data is input directly into the db from the GM interface. The data it holds goes back a few years so the only alternative would be to manually replace special characters. Incidentally, I manually replaced the € symbol in the db in case it had been a cut & paste job from Word or similar but it still displays as a '?' in the output. May be helpful to mention that I use xmlodbc to access and pull the data out from GM - are there any functions for xml I could use to convert these characters on the way out? Quote Link to comment Share on other sites More sharing options...
Xurion Posted April 25, 2008 Share Posted April 25, 2008 <?php $yourvar = "Today I have €3."; $yourvar = str_replace("€", "€", $yourvar); echo $yourvar; ?> Quote Link to comment Share on other sites More sharing options...
cparekh Posted April 25, 2008 Author Share Posted April 25, 2008 Thanks Xurion, but no luck by replacing it either... Any ideas? Quote Link to comment Share on other sites More sharing options...
effigy Posted April 25, 2008 Share Posted April 25, 2008 What encodings are the database and displaying page using? Quote Link to comment Share on other sites More sharing options...
cparekh Posted April 25, 2008 Author Share Posted April 25, 2008 Hi effigy, page is using utf-8, and the db is ISO 8859-1 Western-European Quote Link to comment Share on other sites More sharing options...
effigy Posted April 25, 2008 Share Posted April 25, 2008 If you cannot convert the database to UTF-8, try iconv or simply change your meta tag. Quote Link to comment Share on other sites More sharing options...
cparekh Posted April 25, 2008 Author Share Posted April 25, 2008 Thanks, I'll give that a shot... Quote Link to comment Share on other sites More sharing options...
cparekh Posted April 28, 2008 Author Share Posted April 28, 2008 Hi effigy, tried changing the character set meta tag to charset=iso-8859-1 as well as charset=iso-8859-15, the former being Western European and the latter Western European including support for the € symbol but that didn't work either. I used the same in htmlentities() but none of it seems to make a difference. The $ and £ symbols appear a-ok just not the €. Could the problem lie in the xml from using xmlodbc? I also haven't been able to get the MS 'smart-quotes' to appear properly. Any ideas? conker87 mentioned he uses some code to get rid of them altogether... Quote Link to comment Share on other sites More sharing options...
effigy Posted April 28, 2008 Share Posted April 28, 2008 And what encoding was used when this data was inserted into the database? Without knowing this, I'm not sure how the Euro worked its way in there. You can determine how it's being identified with a combination of MySQL's SUBSTRING and HEX. Smart quotes do not exist in 8859-1. You'll have to replace them with normal quotes. Quote Link to comment Share on other sites More sharing options...
cparekh Posted April 29, 2008 Author Share Posted April 29, 2008 Hi all, firstly, much appreciation for all your help. Due to a time crunch I've had to take an 'easy' way to sort this out for the moment; Thankfully the € symbol only appeared in a few spots and I've done the necessary currency conversions and we're now using £! As for the 'smart-quotes' these also only appear in small amounts of very specific text - I've done a simple string replace for the '?' marks into single quotes. Not ideal for the long term but it'll do for now A good post to read more about 'smart-quotes' is here http://www.phpfreaks.com/forums/index.php/topic,167355.0.html Thanks again, C. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.