Jump to content

Archived

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

DapperDanMan

info from mysql displaying ? instead of '

Recommended Posts

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?

Share this post


Link to post
Share on other sites
try running the output through htmlentities, it's probably from a dodgy character set (or copy/paste from word).

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Ah, man. That's what I ended up doing, I was hoping you didn't have to.
It would be good to know.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.