PHP/MySQL storing unusual characters!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ChrisF79
Forum Commoner
Posts: 26
Joined: Tue Apr 01, 2008 8:26 pm

PHP/MySQL storing unusual characters!

Post by ChrisF79 »

Greetings:

I have a regex that goes through some source code and finds 3 - Attached and stores it as $garage_spaces. If I then do an echo $garage_spaces, I don't have the   but just a space. That's fine enough. When I insert this into a MySQL table, it just looks like "3 - Attached" which is again fine. However, when I do a select and pull the garage field, I get weird ascii characters instead of the spaces. It looks like 3�-�Attached for some reason. It is driving me nuts! Anybody know what I'm doing wrong or what I could try to do to fix this?

Thank you so much!
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: PHP/MySQL storing unusual characters!

Post by pickle »

I'm not entirely sure what you're trying to accomplish, but when those � characters show up, it's a good sign you've got your encoding wrong somewhere.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
ChrisF79
Forum Commoner
Posts: 26
Joined: Tue Apr 01, 2008 8:26 pm

Re: PHP/MySQL storing unusual characters!

Post by ChrisF79 »

pickle wrote:I'm not entirely sure what you're trying to accomplish, but when those � characters show up, it's a good sign you've got your encoding wrong somewhere.
Thanks for the reply. I have my database set as utf8 and I'm developing locally on my Mac using MAMP. Where else would the encoding be off?
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: PHP/MySQL storing unusual characters!

Post by flying_circus »

What is your page encoding?

you can send a header at the top of your PHP file like

Code: Select all

header('Content-type: text/html; charset=UTF-8');
and you can also specify it in your html head, with a meta tag

Code: Select all

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
You must also user PHP's preg* functions and specify the 'u' option for unicode.
ChrisF79
Forum Commoner
Posts: 26
Joined: Tue Apr 01, 2008 8:26 pm

Re: PHP/MySQL storing unusual characters!

Post by ChrisF79 »

I'm not at home now but I'm almost sure that's what my problem is.
Post Reply