Jump to content

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...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.