Results 1 to 8 of 8

Thread: mysql reject "funny hyphen"

  1. #1

    Thread Starter
    Frenzied Member StrangerInBeijing's Avatar
    Join Date
    Mar 2005
    Location
    Not in Beijing
    Posts
    1,666

    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

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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 (—).

  3. #3

    Thread Starter
    Frenzied Member StrangerInBeijing's Avatar
    Join Date
    Mar 2005
    Location
    Not in Beijing
    Posts
    1,666

    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?

  4. #4
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    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

  5. #5

    Thread Starter
    Frenzied Member StrangerInBeijing's Avatar
    Join Date
    Mar 2005
    Location
    Not in Beijing
    Posts
    1,666

    Re: mysql reject "funny hyphen"

    first time ever..sorry

    Yes, after I manually replaced that "dash hyphens" with normal ones, the data inserted ok.

  6. #6
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: mysql reject "funny hyphen"

    i dont know if this will help you:

    http://www.oreillynet.com/onlamp/blo..._latin1_t.html
    My usual boring signature: Something

  7. #7
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: mysql reject "funny hyphen"

    Quote 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
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  8. #8

    Thread Starter
    Frenzied Member StrangerInBeijing's Avatar
    Join Date
    Mar 2005
    Location
    Not in Beijing
    Posts
    1,666

    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
  •  



Click Here to Expand Forum to Full Width