Location: PHPKode > scripts > UTF8 to UCS convertor > utf8-to-ucs-convertor-0-1/utf8UcsClass.php
<?php
	//****************************************
	//*
	//*Convert arabic string from UTF8 to UCS
	//*
	//*
	//*Tariq Momani
	//*
	//*2009-07-05
	//*
	//****************************************
	class utf8UcsClass{
		function  utf8UcsClass(){
			$this->utf8Array=array('21','22','23','24',
						'D9AA','26','27','28',
						'29','D9AD','2B','D88C',
						'2D','2E','2F','30',
						'31','32','33','34',
						'35','36','37','38',
						'39','3A','D89B','3C',
						'3D','3E','D89F','D8A1',
						'D8A2','D8A3','D8A4','D8A5',
						'D8A6','D8A7','D8A8','D8A9',
						'D8AA','D8AB','D8AC','D8AD',
						'D8AE','D8AF','D8B0','D8B1',
						'D8B2','D8B3','D8B4','D8B5',
						'D8B6','D8B7','D8B8','D8B9',
						'D8BA','5B','5D','D980',
						'D981','D982','D983','D984',
						'D985','D986','D987','D988',
						'D989','D98A','D98B','D98C',
						'D98D','D98E','D98F','D990',
						'D991','D992','D9B1','D9B0',
						'D9AC','E2809D','E2809C','20');
								
			$this->ucsArray=array('0021','0022','0023','0024',
						'066A','0026','0027','0028',
						'0029','066D','002B','060C',
						'002D','002E','002F','0660',
						'0661','0662','0663','0664',
						'0665','0666','0667','0668',
						'0669','003A','061B','003C',
						'003D','003E','061F','0621',
						'0622','0623','0624','0625',
						'0626','0627','0628','0629',
						'062A','062B','062C','062D',
						'062E','062F','0630','0631',
						'0632','0633','0634','0635',
						'0636','0637','0638','0639',
						'063A','005B','005D','0640',
						'0641','0642','0643','0644',
						'0645','0646','0647','0648',
						'0649','064A','064B','064C',
						'064D','064E','064F','0650',
						'0651','0652','0671','0670',
						'066C','201D','201C','0020');

			$this->specialChar=array('0','1','2','3',
						'4','5','6','7',
						'8','9',' ','!',
						'#','$','&','(',
						')','\'','+','-',
						'.','\\');
		}
		
		function getString($string){
			$this->utf8UcsClass();
			$hexa='';
			$index=0;
			for($i=0;$i<strlen($string);$i++){
				if(in_array($string[$i],$this->specialChar)){
					$hexa.=$this->stringUTF8UCS($string[$i]);
				}
				else{
					$index++;
					$str.=$string[$i];
					if($index==2){
						$hexa.=$this->stringUTF8UCS($str);
						$index=0;
						$str='';
					}
				}
			}
			return $hexa;
		}
		
		function stringUTF8UCS($char){
			$utf8=bin2hex($char);
			for($i=0;$i<sizeof($this->utf8Array);$i++){
				if(strtoupper($utf8)==$this->utf8Array[$i]){
					return $this->ucsArray[$i];
				}
			}
		}
	}

?>
Return current item: UTF8 to UCS convertor