Location: PHPKode > scripts > Unicode to Arabic > unicode-to-arabic/class.Unicode2Arabic.php
<?php
//Class Unicode2Arabic converts check if given Hex code is Arabic 
//then converts Hex codes to Character HEX inorder to display in browser
//Class also helps to decode Unicode to respective Character code based on 
//database (MySQL /MS-SQL) user is using.

#@ Class Name : Unicode2Arabic
#@ Author : Satish Kumar
#@ Email : hide@address.com
class Unicode2Arabic
{
public $message;
function __constuct()
{
	$message="";
}

//convert HEX  to Character HEX
function uni2arabic($uni_str) 
{ 
		$text_str = ''; 
		for($i=0; $i<strlen($uni_str); $i+=4){
		$text_str .= "&#x".substr($uni_str,$i,4).";";
		}
		return $text_str; 
}  
	
//check if string message is arabic
function chkArabic($uni_str) 
{ 
		$text_str = ''; 
		for($i=0; $i<strlen($uni_str); $i+=4){
		$text_str = substr($uni_str,$i,4);
		$ascii=hexdec($text_str); //CONVERT TO DECIMAL

				if($ascii >= 1536 and $ascii <= 1791)
				{
				return "1";
				exit;
				}		
		
		}
		return "2"; 
} 
	

function process_url_mssql()
{


	if(trim($this->message)!="")
	{	
	$nmessage =html_entity_decode($this->message, ENT_NOQUOTES, 'UTF-8');
	$this->message = mb_convert_encoding($nmessage, 'ISO-8859-6', 'UTF-8');
	}
	else
	$this->message=" ";

}	


}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="ar" xml:lang="ar" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<?php
$msg="0031062D0628";//Arabic Hex codes 

//Create object of main class
$cc=new Unicode2Arabic();
// message

$cc->message=$msg;

//check if message recived is arabic 1= arabic and 2-=english
$cc->arabic=$cc->chkArabic($cc->message);

if($cc->arabic=="1")
{
	//convert message received into string
	//inorder to insert data into MYSQL 
	$hs =$cc->uni2arabic($cc->message);
	
	//inoder to insert data into MSSQL
	$hs1 =$cc->process_url_mssql();
	
	echo "Message : ".html_entity_decode($hs, ENT_NOQUOTES, 'ISO-8859-6')."<br>";
	echo "Language : Arabic<br>";
		
}
else
{
	$hs =$cc->message;
	echo "Message : ".$hs."<br>";		
	echo "Language : English<br>";
}

?>

</body>
</html>
Return current item: Unicode to Arabic