DapperDanMan Posted July 8, 2006 Share Posted July 8, 2006 I have no idea what is going on. the information stored in the mysql database displays correctly within the database:mysql example - “Give th’ man a drink, Belk.However, when it is called from a php file it displays as follows:�Give th� man a drink, Belk.I really am stumped why it cannot pull the text from the database and display it properly. Can anyone enlighten me why it is doing this to the quotes and apostrophes? Quote Link to comment https://forums.phpfreaks.com/topic/14058-info-from-mysql-displaying-instead-of/ Share on other sites More sharing options...
pipeten Posted July 8, 2006 Share Posted July 8, 2006 try running the output through htmlentities, it's probably from a dodgy character set (or copy/paste from word). Quote Link to comment https://forums.phpfreaks.com/topic/14058-info-from-mysql-displaying-instead-of/#findComment-54950 Share on other sites More sharing options...
ShogunWarrior Posted July 8, 2006 Share Posted July 8, 2006 I imagine it's todo with encoding, you could check out what encoding is used in the mySQL field and then convert from/to that to try and remedy it after extracting the text. Quote Link to comment https://forums.phpfreaks.com/topic/14058-info-from-mysql-displaying-instead-of/#findComment-54951 Share on other sites More sharing options...
DapperDanMan Posted July 8, 2006 Author Share Posted July 8, 2006 When you say "encoding" do you mean charset? If so, it is UTF-8 Unicode (utf8). Now my collation is different. It is latin_general_ci. Could this be the problem? Quote Link to comment https://forums.phpfreaks.com/topic/14058-info-from-mysql-displaying-instead-of/#findComment-54954 Share on other sites More sharing options...
ShogunWarrior Posted July 8, 2006 Share Posted July 8, 2006 I've always used latin_general_ci too and I don't know of any problems with collation so I doubt that's the problem.I had this problem with a Firebird database and ended up str_Replace 'ing stuff because it wasn't worth figuring out at the time.I'm no expert on encoding so maybe looking into converting to UTF-8 again or ISO-8859-1 might do something. Quote Link to comment https://forums.phpfreaks.com/topic/14058-info-from-mysql-displaying-instead-of/#findComment-54956 Share on other sites More sharing options...
DapperDanMan Posted July 9, 2006 Author Share Posted July 9, 2006 Okay, after some more research (and banging head against the wall) I discovered that the text I am copying has "fancy" quotes and apostrophes. So I tried the other post about htmlentities, but no luck. It didn't change the quotes, just showed the line breaks. So here is the problem, the text I am pulling from is actually of a website and the quotes slant inward. If I change them to the standard quotes that are absolutely vertical, it works fine. See the above example for the style of quotes.Does anyone have any clue why it works on another website, but I cannot pull them from the database? Quote Link to comment https://forums.phpfreaks.com/topic/14058-info-from-mysql-displaying-instead-of/#findComment-55273 Share on other sites More sharing options...
DapperDanMan Posted July 9, 2006 Author Share Posted July 9, 2006 Well, I have a workaround right now. I am using a str_replace() when inserting the text into the database: $pattern = array("“", "’"); $replacement = array("\"", "\'"); $synop = str_replace($pattern, $replacement, $synopsis);I then use a stripslashes() when I call the information from the database. It isn't the best way I know, but it does work. I would still like to figure out why it is causing problems in the first place and correct it, so if anyone knows, I would really appreciate the help.Thank you Quote Link to comment https://forums.phpfreaks.com/topic/14058-info-from-mysql-displaying-instead-of/#findComment-55287 Share on other sites More sharing options...
ShogunWarrior Posted July 9, 2006 Share Posted July 9, 2006 Ah, man. That's what I ended up doing, I was hoping you didn't have to.It would be good to know. Quote Link to comment https://forums.phpfreaks.com/topic/14058-info-from-mysql-displaying-instead-of/#findComment-55295 Share on other sites More sharing options...
DapperDanMan Posted July 9, 2006 Author Share Posted July 9, 2006 Well I'm happy I am not the only one, but sad that you had to face the same conclusion. I'm thinking about contacting my hosting service and seeing if they have a suggestion. Quote Link to comment https://forums.phpfreaks.com/topic/14058-info-from-mysql-displaying-instead-of/#findComment-55301 Share on other sites More sharing options...
ShogunWarrior Posted July 9, 2006 Share Posted July 9, 2006 I created a database+table to try and recreate it and inserted some foreign characters.When I output them from a SELECT some came out as ?.I tried utf8decode,utf8encodem,htmlentities, encoding before insertion but nothing worked.I got the same ?'s using PHPMyAdmin AND the MySQL client so it seems there's a bigger problem than something we should be doing in PHP. Quote Link to comment https://forums.phpfreaks.com/topic/14058-info-from-mysql-displaying-instead-of/#findComment-55324 Share on other sites More sharing options...
DapperDanMan Posted July 11, 2006 Author Share Posted July 11, 2006 Wow ShogunWarrior! I didn't expect anyone to do that, thank you very much for checking it out yourself. I have tried dozens of collation variables. I have noticed that on certain occasions, it causes the text inserted into the database to be converted to the '?'. I still need to do more testing and see if I can repeat the problem where that happens. I've also placed a question to my hositing service to see if they know anything about the problem. But I feel that may be a longshot. If I hear back from them with relevent information, I will post it here. Quote Link to comment https://forums.phpfreaks.com/topic/14058-info-from-mysql-displaying-instead-of/#findComment-55987 Share on other sites More sharing options...
DapperDanMan Posted July 11, 2006 Author Share Posted July 11, 2006 Oh yeah, in the meantime. To save anyone else the added trouble, I've added more characters into the str_replace as follows: $pattern = array("“", "’", "”", "‘", "…"); $replacement = array("\"", "\'", "\"", "\'", "..."); $synop = str_replace($pattern, $replacement, $synopsis);Again, make sure this goes into the code before INSERTing into the mysql database. Now, can anyone tell me why it works on this site? Surely this is ran off some kind of database, right? Why do the special characters work here, but I cannot figure it out on my site? Quote Link to comment https://forums.phpfreaks.com/topic/14058-info-from-mysql-displaying-instead-of/#findComment-55989 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.