phpfan Posted March 18, 2007 Share Posted March 18, 2007 Hi all, I am trying to save Greek strings on my MySql database but although that the values appear correct when i retrieve them from the database when i do a "browse" in my tables the Greek values appear as strings on coded characters such as (Λαστιχα). I have try to change the Collation of the Greek fields to greek_bin and greek_latin_ci but i still have the same problem. Is there any solution?? I am using MySQL client version: 5.0.33 and PhpMyAdmin version 2.92 Thank You in Advance Quote Link to comment Share on other sites More sharing options...
btherl Posted March 20, 2007 Share Posted March 20, 2007 It's likely you are storing them that way. Try the following (for a post variable named "var"): $var_decoded = urldecode($_POST['var']); $var_escaped = mysql_real_escape_string($var_decoded); Then put $var_escaped in the database. Do you know what encoding your data is in? UTF8? Quote Link to comment Share on other sites More sharing options...
phpfan Posted March 21, 2007 Author Share Posted March 21, 2007 Hi I have try this and i get a result look like this ÁíôñÝáò. The variable that i try to store was Αντρέας. So the encoding has changed but not to the required... The encoding of my data is UTF-8... Thank you btherl ,any further suggestions... Quote Link to comment Share on other sites More sharing options...
btherl Posted March 21, 2007 Share Posted March 21, 2007 Oops.. it looks like php can't handle those types of entites. And I was using the wrong function too.. Anyway, back to the problem I found this function on the php website function utf8_replaceEntity($result){ $value = (int)$result[1]; $string = ''; $len = round(pow($value,1/8)); for($i=$len;$i>0;$i--){ $part = ($value & (255>>2)) | pow(2,7); if ( $i == 1 ) $part |= 255<<(8-$len); $string = chr($part) . $string; $value >>= 6; } return $string; } function utf8_html_entity_decode($string){ return preg_replace_callback( '/&#([0-9]+);/u', 'utf8_replaceEntity', $string ); } If you feed your string into that, it will convert the data from html entities into utf8. I tested it here, and with the sample string you gave it produces greek characters. If you have any trouble with it let me know. You should call utf8_html_entity_decode($str) to do the decoding. Quote Link to comment Share on other sites More sharing options...
phpfan Posted March 21, 2007 Author Share Posted March 21, 2007 Hi btherl I must do something wrong because the variable that supposes to have the decode value is empty... function utf8_replaceEntity($result){ $value = (int)$result[1]; $string = ''; $len = round(pow($value,1/8)); for($i=$len;$i>0;$i--){ $part = ($value & (255>>2)) | pow(2,7); if ( $i == 1 ) $part |= 255<<(8-$len); $string = chr($part) . $string; $value >>= 6; } return $string; } function utf8_html_entity_decode($string){ return preg_replace_callback('/&#([0-9]+);/u', 'utf8_replaceEntity',$string); } $myname = utf8_html_entity_decode($name); I pass the variable $name to the function which is a Greek string and then try to store the result of the decoding in the variable $myname but the variable $myname appears to be empty when i try to use it... Any ideas..... ??? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.