...

View Full Version : problem encoding utf-8



skmd
12-26-2007, 02:35 PM
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

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
and added

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.

skmd
12-26-2007, 05:51 PM
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 .
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;
$result= mysql_query($SQL) or die(mysql_error());

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

}

oesxyl
12-26-2007, 06:44 PM
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.



<form accept-charset="utf-8" ...


Some details about this issue you could find to:

http://www.crazysquirrel.com/computing/general/form-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

skmd
12-26-2007, 07:05 PM
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?

oesxyl
12-26-2007, 07:44 PM
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

skmd
12-26-2007, 07:50 PM
ok, I found the escapestring function somewhare in the script ,here its

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?

oesxyl
12-26-2007, 08:24 PM
ok, I found the escapestring function somewhare in the script ,here its

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

skmd
12-26-2007, 08:40 PM
I think its not a problem since the admins only will add new Items and thank you so much for being helpful

ralph l mayo
12-26-2007, 08:50 PM
Try expanding that htmlentities call to htmlentities($text, ENT_NOQUOTES, "UTF-8")

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

skmd
12-26-2007, 09:13 PM
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

oesxyl
12-26-2007, 09:33 PM
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

skmd
12-26-2007, 11:44 PM
I forgot to complete the sentence, its correct now
thank you for noticing me



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum