Jump to content


Photo

info from mysql displaying ? instead of '


  • Please log in to reply
11 replies to this topic

#1 DapperDanMan

DapperDanMan
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 08 July 2006 - 10:05 PM

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?
[a href="http://www.brierrowstudio.com" target="_blank"]http://www.brierrowstudio.com[/a]

#2 pipeten

pipeten
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 08 July 2006 - 10:09 PM

try running the output through htmlentities, it's probably from a dodgy character set (or copy/paste from word).

#3 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 08 July 2006 - 10:11 PM

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.
<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd

#4 DapperDanMan

DapperDanMan
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 08 July 2006 - 10:20 PM

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?
[a href="http://www.brierrowstudio.com" target="_blank"]http://www.brierrowstudio.com[/a]

#5 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 08 July 2006 - 10:23 PM

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.
<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd

#6 DapperDanMan

DapperDanMan
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 09 July 2006 - 08:17 PM

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?
[a href="http://www.brierrowstudio.com" target="_blank"]http://www.brierrowstudio.com[/a]

#7 DapperDanMan

DapperDanMan
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 09 July 2006 - 08:41 PM

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


[a href="http://www.brierrowstudio.com" target="_blank"]http://www.brierrowstudio.com[/a]

#8 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 09 July 2006 - 09:09 PM

Ah, man. That's what I ended up doing, I was hoping you didn't have to.
It would be good to know.
<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd

#9 DapperDanMan

DapperDanMan
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 09 July 2006 - 09:50 PM

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.
[a href="http://www.brierrowstudio.com" target="_blank"]http://www.brierrowstudio.com[/a]

#10 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 09 July 2006 - 11:50 PM

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.
<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd

#11 DapperDanMan

DapperDanMan
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 11 July 2006 - 03:43 AM

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.
[a href="http://www.brierrowstudio.com" target="_blank"]http://www.brierrowstudio.com[/a]

#12 DapperDanMan

DapperDanMan
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 11 July 2006 - 03:47 AM

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?

[a href="http://www.brierrowstudio.com" target="_blank"]http://www.brierrowstudio.com[/a]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users