Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    New Coder
    Join Date
    Dec 2007
    Posts
    96
    Thanks
    8
    Thanked 1 Time in 1 Post

    problem encoding utf-8

    im using a built2go movies script , I want to enter arabic discription for the movies so I changed the database to UTF-8 and added at the headers
    PHP Code:
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    and added
    PHP Code:
    mysql_query("SET character_set_client=utf8"); 
    mysql_query("SET character_set_connection=utf8"); 
    mysql_query("SET character_set_database=utf8"); 
    mysql_query("SET character_set_results=utf8"); 
    mysql_query("SET character_set_server=utf8"); 
    for the connecting to database file
    but the problem is when I insert movies in arabic from the admin panel it doesnt insert proparly and looks like this بÙ
    but if I inserted them through php my admin it works great .
    does anybody knows this kind of problems? , any ideas will be appreciated.
    Last edited by skmd; 12-26-2007 at 03:14 PM.

  • #2
    New Coder
    Join Date
    Dec 2007
    Posts
    96
    Thanks
    8
    Thanked 1 Time in 1 Post
    Here is the function responsable about adding a new item (movie) to the database , if any body can check it if there is anything prevent the text to be added in utf-8 format .
    PHP Code:
    function AddMovie(){

            
    $this->UploadMoviePic();

            if (!
    $this->_movieValues['Adderror']){
                if (
    $_POST['url']){
                    
    $url addslashes($_POST['url']);
                    if (!
    eregi("http://"$url)){
                            
    $url "http://$url";
                    }
                }
                if (
    $this->_movieValues['aspdate']){
                       
    $sponsordate $this->_movieValues['aspdate'];
                       
    $total_sp_clicks=$_POST['totalspclicks'];
                       
    $clicks_purchased=$_POST['clickspr'];
                       
    $totclicks_purchased $_POST['allspclicks'];
                       
    $sponsor '1';
                }
                if (
    $_POST['origdate']){
                   
    $newdate $_POST['movyear']."-".$_POST['movmonth']."-".$_POST['movday'];
                    
    $origdate strtotime($newdate);
                } else {
                   
    $origdate time();
                }
                
    $releasedate $_POST['relyear']."-".$_POST['relmonth']."-".$_POST['relday'];
                    
    $releasedate strtotime($releasedate);

                
    $descr ereg_replace("(\r\n|\n|\r)""<br />"EscapeString($_POST['areview']));
                
    $other_info ereg_replace("(\r\n|\n|\r)""<br />"EscapeString($_POST['other_info']));
                
    $SQL "INSERT INTO ".TABLE_PREFIX."movies (mid,mtitle,adminreview,other_info,mdate,mcatid ,murl, release_date,mpaa_rating,runtime, director, writer, distributor,mstatus,picture,admin_rating,acomments)
            VALUES ('','"
    .EscapeString($_POST['title'])."','$descr','$other_info','".time()."','".valid_id($_POST['cid'])."','$url','$releasedate',
            '"
    .EscapeString($_POST['mpaarating'])."','".EscapeString($_POST['runtime'])."','".EscapeString($_POST['director'])."',
            '"
    .EscapeString($_POST['writer'])."','".EscapeString($_POST['dist'])."','{$_POST['mstatus']}',
            '"
    .$this->_movieValues['UploadedImage']."','".$_POST['voteval']."', '{$this->_movieValues['adminComment']}')";
                
    //echo $SQL;
                
    $resultmysql_query($SQL) or die(mysql_error());

            } else {
                return 
    $this->_movieValues['Adderror'];
            }

        } 
    Last edited by skmd; 12-26-2007 at 06:21 PM.

  • #3
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    first try to find where is the problem, mysql, php or html, I presume is in html part.
    If I'm right you can add a accept-charset="utf-8" to the form and modify the php code to convert to/from utf-8.

    Code:
    <form accept-charset="utf-8" ...
    Some details about this issue you could find to:

    http://www.crazysquirrel.com/computi...-encoding.jspx

    use php function utf8-encode, utf8-decode or iconv for conversion.

    http://www.php.net/manual/en/function.utf8-encode.php
    http://www.php.net/manual/en/function.utf8-decode.php
    http://www.php.net/manual/en/ref.iconv.php

    best regards

  • Users who have thanked oesxyl for this post:

    skmd (12-26-2007)

  • #4
    New Coder
    Join Date
    Dec 2007
    Posts
    96
    Thanks
    8
    Thanked 1 Time in 1 Post
    First of all I want to thank you because you are the only one who answered me since I subscribed in this forum.

    I tried it but it didnt resolve the problem, But I think the proble is in the php code cuz I noticed that the values for "murl" and "acomments" are displayed correctly in the phpmyadmin and my site and both the values are inserted without the ".EscapeString($_POST['******'])." ( I dont know by the way what escapestring do) does this function preventing the data from being inserted correctly or what?
    Last edited by skmd; 12-26-2007 at 07:14 PM.

  • #5
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by skmd View Post
    First of all I want to thank you because you are the only one who answered me since I subscribed in this forum.
    with pleasure, any time.

    I tried it but it didnt resolve the problem, But I think the proble is in the php code cuz I noticed that the values for "murl" and "acomments" are displayed correctly in the phpmyadmin and my site and both the values are inserted without the ".EscapeString($_POST['******'])." ( I dont know by the way what escapestring do) does this function preventing the data from being inserted correctly or what?
    I don't know what EscapeString do, I guess it escape some special chars as '\', ';' or others, look in your source maybe is defined somewhere, I didn't find it in php manual. Try to see how is implemented and try without it if you really not need it.
    Try to follow the data flow:
    - write something in html form and check before any processing to see if is correct, you can use sometring like echo $_POST[...] inside a html p block.
    - test before any function call if is what you want and if is necessary after.

    I have the same problem, not with arabic , and I didn't find a real solution, only specific improvisation as I write above.

    best regards

  • #6
    New Coder
    Join Date
    Dec 2007
    Posts
    96
    Thanks
    8
    Thanked 1 Time in 1 Post
    ok, I found the escapestring function somewhare in the script ,here its
    PHP Code:
    function EscapeString($text){
        
    $text htmlentities($text);
        if (!
    get_magic_quotes_gpc()) {
            
    $text mysql_real_escape_string($text);
        }
        return 
    $text;


    can you try to understand what does this function do cuz i want to remove it and use normal $_POST
    and what language u have problem with?

  • #7
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by skmd View Post
    ok, I found the escapestring function somewhare in the script ,here its
    PHP Code:
    function EscapeString($text){
        
    $text htmlentities($text);
        if (!
    get_magic_quotes_gpc()) {
            
    $text mysql_real_escape_string($text);
        }
        return 
    $text;


    can you try to understand what does this function do cuz i want to remove it and use normal $_POST
    htmlentities - convert chars which have html entities and specials chars to html entities.
    get_magic_quotes_gpc - test the configuration of magic_quotes_gpc

    magic-quotes-gpc variable -> "Sets the magic_quotes state for GPC (Get/Post/Cookie) operations. When magic_quotes are on, all ' (single-quote), " (double quote), \ (backslash) and NUL's are escaped with a backslash automatically."

    mysql_real_escape_string - Escapes special characters in the unescaped_string , taking into account the current character set of the connection so that it is safe to place it in a mysql_query().

    if we put this all together EscapeString is used both for security, escaping specials chars, and conversion to encoding you use in mysql.

    I don't know if is good to remove it, I supose that if the argument of EscapeString is correct, magic_quotes_gpc is on and your mysql settings are correct this must do what you need. Check each of this to see if is something wrong.

    and what language u have problem with?
    not a specific language, this is a encoding problem, appear when somebody cut & paste text with diacritics from different application into a form, .

    best regards

  • #8
    New Coder
    Join Date
    Dec 2007
    Posts
    96
    Thanks
    8
    Thanked 1 Time in 1 Post
    I think its not a problem since the admins only will add new Items and thank you so much for being helpful

  • #9
    Regular Coder ralph l mayo's Avatar
    Join Date
    Nov 2005
    Posts
    951
    Thanks
    1
    Thanked 31 Times in 29 Posts
    Try expanding that htmlentities call to htmlentities($text, ENT_NOQUOTES, "UTF-8")

    There may be other problems, but that's definitely one of them.

  • #10
    New Coder
    Join Date
    Dec 2007
    Posts
    96
    Thanks
    8
    Thanked 1 Time in 1 Post
    ok, I have found the problem the htmlentities() doesnt support utf-8 by default you have to define it (http://www.php.net/htmlentities)
    expanding the htmlentities worked great thats exactly what I want thank you all
    Last edited by skmd; 12-27-2007 at 01:01 AM.

  • #11
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by skmd View Post
    ok, I have found the problem the htmlentities() doesnt support utf-8 (http://www.php.net/htmlentities)
    but expanding the htmlentities worked great thats exactly what I want thank you all
    why did you say that htmlentities did not support utf-8, or I missunderstand something?
    I understand from your link, see parameters, charset section, that support, as third paramaeter, as in ralph l mayo replay.

    best regards

  • #12
    New Coder
    Join Date
    Dec 2007
    Posts
    96
    Thanks
    8
    Thanked 1 Time in 1 Post
    I forgot to complete the sentence, its correct now
    thank you for noticing me


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •