|
-
Dec 11th, 2007, 12:08 AM
#1
Thread Starter
Frenzied Member
mysql reject "funny hyphen"
Hi,
First off, this is not a problem on my local machine (winxp,php, mysql).
It's is a problem on the live server (win2k3server, php, mysql) and according to "select version();" I run the the same version of mysql on both machinces.
I created a data capturing page where I copy and paste data into from another partner site for the moment.
Note that i both tried addslashes and mysql_real_escape_string to deal with this.
I realized that allthought things work fine on my local machine, a mysql error occur when saving the same data to the live server.
After much debugging, I realized it's because of a hyphen looking character (but acutally nearly double as long as a normal hyphen), and tis' treated as an invalide character.
When I try do a strreplace in php (i edit in dreamweaver), and i copy the long hyphen thing into "$string = str_replace("–","-",$string);", it does not replace it. But even so, this will solve my problem with only one "strange" character...what about others that come up in the future?
I'm using php 5 and mysql 5.0.45-community nt
-
Dec 11th, 2007, 12:19 AM
#2
Re: mysql reject "funny hyphen"
What's the error message?
By the way, the 'funny hyphens' are actually dash characters: en dash (–) and em dash (—).
-
Dec 11th, 2007, 12:25 AM
#3
Thread Starter
Frenzied Member
Re: mysql reject "funny hyphen"
ERROR 1366 (HY000): Incorrect string value: '\xA8C
'scuse my ignorance..how to make sure user's dont enter characters that might cause problems for mysql?
or how to make mysql handle them without issues?
my tables, everything is using utf-8, and i can even insert and read chinese from the database now. why would this dash things be a problem?
-
Dec 11th, 2007, 07:48 PM
#4
Re: mysql reject "funny hyphen"
please dont bump your threads.
Are you sure it has to do with the Hyphen? It might not have anything to do with them.
My usual boring signature: Something
-
Dec 11th, 2007, 09:02 PM
#5
Thread Starter
Frenzied Member
Re: mysql reject "funny hyphen"
first time ever..sorry
Yes, after I manually replaced that "dash hyphens" with normal ones, the data inserted ok.
-
Dec 11th, 2007, 09:05 PM
#6
Re: mysql reject "funny hyphen"
My usual boring signature: Something
-
Dec 13th, 2007, 06:10 AM
#7
Re: mysql reject "funny hyphen"
 Originally Posted by StrangerInBeijing
'scuse my ignorance..how to make sure user's dont enter characters that might cause problems for mysql?
or how to make mysql handle them without issues?
my tables, everything is using utf-8, and i can even insert and read chinese from the database now. why would this dash things be a problem?
It looks like you were trying to insert a UTF-8 character. Check these:
http://www.phpwact.org/php/i18n/utf-8/mysql
http://dev.mysql.com/doc/refman/5.0/...t-unicode.html
-
Dec 18th, 2007, 03:47 AM
#8
Thread Starter
Frenzied Member
Re: mysql reject "funny hyphen"
i know very little regex, so why this work, i dont know, but work it does....
Code:
function fix_bad_chars($text) {
$text = preg_replace( '/\p{Pd}+((?= )|$)/u', '-', $text );
$text = preg_replace( '/((?<= )|^)\p{Pd}+(?![\p{N}\p{Sc}])/u', '-', $text );
return $text;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|