Problem With Hebrew from Database

Topics: Developer Forum
Oct 23, 2011 at 12:07 PM

Hello

I am trying to show some data from my database on a .xlsx file. My data is in hebrew and english.

it works very well for the english fileds, but the hebrew filed ramain empty!

i have tryed to use utf8_encode() function on the hebrew fileds, then it shows some gibrish instead of hebrew.

the strangest thing is that when i type the hebrew in the php file, it works fine!

 

i would like to know id someone had this problem in the past, and if someone knows the solution for it.

Thanks,

Tomer

Oct 23, 2011 at 2:13 PM

Hi tomer, I worked with PHPExcel and it has many problems with hebrew..I was trying to do something else but still I didn't find a solution.. :(

 

Oct 24, 2011 at 7:48 AM

no experience with hebrew, but I have with all kinds of Asian characters. As long as it's utf-8 it has worked fine for me ;) What character encoding does you db use? and if your db isn't using utf-8, where are you converting it? Do you explicitely tell mysql to use utf-8 over the db connection?

Feb 12, 2012 at 10:43 AM

Thank you guys for the help. i used another solotion. you can see it here:

function Decode($text){
    $jibberish = Array("à", "á", "â", "ã", "ä", "å", "æ", "ç", "è", "é", "ë", "ê", "ì", "î", "í", "ð", "ï", "ñ", "ò", "ô", "ó", "ö", "õ", "÷", "ø", "ù", "ú");
    $hebrew =      Array("א", "ב", "ג", "ד", "ה", "ו", "ז", "ח", "ט", "י", "כ", "ך", "ל", "מ", "ם", "נ", "ן", "ס", "ע", "פ", "ף", "צ", "ץ", "ק", "ר", "ש", "ת");
    $utf8marker=chr(128);
    $count=0;
    $flag = 0;
    $dcoded ='';
    while(isset($text{$count})){
        if($text{$count}>=$utf8marker) {
            $parsechar=substr($text,$count,2);
            $count+=2;
        } else {
            $parsechar=$text{$count};
            $count++;
        }
        $ch = $parsechar;
        $l2 = count($jibberish);
        for($j=0;$j<$l2;$j++){       
            if($jibberish[$j] == $ch){
                $dcoded .= $hebrew[$j];
                $flag = 1;
                break;
            }
            if($j==($l2-1) && $flag != 1){
                $dcoded .= $ch; //It's not jibberish - just add it as is
                break;
            }
        }
        $flag = 0; 
     }       
         return SpecialChars($dcoded);
}
function SpecialChars($val) {
    $val = str_replace(  "&amp;"     , "&"          , $val );
    $val = str_replace(  "&gt;"      , ">"          , $val );
    $val = str_replace(  "&lt;"      , "<"          , $val );
    $val = str_replace(  "&quot;"    , "\""         , $val );
    $val = str_replace(  "&#33;"     , "!"          , $val );
    $val = str_replace(  "&#39;"     , "'"          , $val ); // IMPORTANT: It helps to increase sql query safety.
    return $val;
}

function Decode($text){
	$jibberish = Array("&#224;", "&#225;", "&#226;", "&#227;", "&#228;", "&#229;", "&#230;", "&#231;", "&#232;", "&#233;", "&#235;", "&#234;", "&#236;", "&#238;", "&#237;", "&#240;", "&#239;", "&#241;", "&#242;", "&#244;", "&#243;", "&#246;", "&#245;", "�", "&#248;", "&#249;", "&#250;");
	$hebrew = 	 Array("�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�", "�");
	$utf8marker=chr(128);
    $count=0;
	$flag = 0; 
	$dcoded ='';
	while(isset($text{$count})){
		if($text{$count}>=$utf8marker) {
			$parsechar=substr($text,$count,2);
			$count+=2;
		} else {
			$parsechar=$text{$count};
			$count++;
		}
		$ch = $parsechar;
		$l2 = count($jibberish);
		for($j=0;$j<$l2;$j++){		
			if($jibberish[$j] == $ch){
				$dcoded .= $hebrew[$j];
				$flag = 1;
				break;
			}
			if($j==($l2-1) && $flag != 1){
				$dcoded .= $ch; //It's not jibberish - just add it as is
				break;
		    }
		}
		$flag = 0;  
     }		
		 return SpecialChars($dcoded);
}
function SpecialChars($val) {
	$val = str_replace(  "&amp;"     , "&"          , $val );
	$val = str_replace(  "&gt;"      , ">"          , $val );
	$val = str_replace(  "&lt;"      , "<"          , $val );
	$val = str_replace(  "&quot;"    , "\""         , $val );
	$val = str_replace(  "&#33;"     , "!"          , $val );
	$val = str_replace(  "&#39;"     , "'"          , $val ); // IMPORTANT: It helps to increase sql query safety.
	return $val;
}