Jump to content

info from mysql displaying ? instead of '


DapperDanMan

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?
Link to comment
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.
Link to comment
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?
Link to comment
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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.