Jump to content

encoding problem


vividona

Recommended Posts

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

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

  • 3 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.