Page 1 of 1

PHP/MySQL storing unusual characters!

Posted: Tue Mar 16, 2010 12:06 pm
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!

Re: PHP/MySQL storing unusual characters!

Posted: Tue Mar 16, 2010 12:41 pm
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.

Re: PHP/MySQL storing unusual characters!

Posted: Tue Mar 16, 2010 12:46 pm
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?

Re: PHP/MySQL storing unusual characters!

Posted: Tue Mar 16, 2010 12:56 pm
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.

Re: PHP/MySQL storing unusual characters!

Posted: Tue Mar 16, 2010 1:27 pm
by ChrisF79
I'm not at home now but I'm almost sure that's what my problem is.