vividona Posted July 17, 2011 Share Posted July 17, 2011 I made small website with two languages (English/Arabic) but Arabic language content always shows in very strange characters when I fetch them from database I made this function to encode it. but when I do this English Language content disappeared. public function enco($item) { if(isset($_SESSION['lang'])){ $lang = $this->sanitStr($_SESSION['lang']); if($lang == $this->sanitStr('Arabic')){ return iconv('UTF-8', 'windows-1256', $item); }else{ return $item; } } } I changed encoding in my index page also echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head> <meta http-equiv="Content-Type" content="text/html; charset='.$sessInfo->langEncoding().'" /> in database I change this public function execute_connection() { $this->connection = mysql_connect($this->config['dbserver'], $this->config['dbuser'], $this->config['dbpass']); mysql_set_charset('utf8',$this->connection); mysql_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'", $this->connection); if(!$this->connection){ $this->ThrowException("Sorry, unable to connect to the database!."); } $this->selectBhlDb($this->config['dbname']); } Link to comment https://forums.phpfreaks.com/topic/242167-encoding-problem/ Share on other sites More sharing options...
phpmady Posted July 17, 2011 Share Posted July 17, 2011 Hi, <meta http-equiv="Content-Type" content="text/html; charset='utf-8" /> The above meta tag with utf-8, will make the task easier for any language. Thanks, Link to comment https://forums.phpfreaks.com/topic/242167-encoding-problem/#findComment-1243706 Share on other sites More sharing options...
vividona Posted July 18, 2011 Author Share Posted July 18, 2011 Hi, <meta http-equiv="Content-Type" content="text/html; charset='utf-8" /> The above meta tag with utf-8, will make the task easier for any language. Thanks, Hi, echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head> <meta http-equiv="Content-Type" content="text/html; charset='.$sessInfo->langEncoding().'" /> I made this function which put utf-9 as default. But when user select Arabic language, utf-8 will not read Arabic charset (it should be windows-1256) $sessInfo->langEncoding() Link to comment https://forums.phpfreaks.com/topic/242167-encoding-problem/#findComment-1244032 Share on other sites More sharing options...
phpmady Posted August 2, 2011 Share Posted August 2, 2011 Hi, I am still able to read Arabic Characters by using UTF-8 Thanks Link to comment https://forums.phpfreaks.com/topic/242167-encoding-problem/#findComment-1250832 Share on other sites More sharing options...
arjang Posted August 2, 2011 Share Posted August 2, 2011 i had the same problem with persian and english. i changed the character set in persian table to utf8 and added this code in the connection file mysql_set_charset('utf8'); everything woks well Link to comment https://forums.phpfreaks.com/topic/242167-encoding-problem/#findComment-1250847 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.