I have some problems comparing an array with Norwegian characters with utf8 character.
All characters except special Norwegian characters (æ, ø, å) work fine.
function isNorwegianChar($Char)
{
$aNorwegianChars = array('a', 'A', 'b', 'B', 'c', 'C', 'd', 'D', 'e', 'E', 'f', 'F', 'g', 'G', 'h', 'H', 'i', 'I', 'j', 'J', 'k', 'K', 'l', 'L', 'm', 'M', 'n', 'N', 'o', 'O', 'p', 'P', 'q', 'Q', 'r', 'R', 's', 'S', 't', 'T', 'u', 'U', 'v', 'V', 'w', 'W', 'x', 'X', 'y', 'Y', 'z', 'Z', 'æ', 'Æ', 'ø', 'Ø', 'å', 'Å', '=', '(', ')', ' ', '-');
$iArrayLength = count($aNorwegianChars);
for($iCount = 0; $iCount < $iArrayLength; $iCount++)
{
if($aNorwegianChars[$iCount] == $Char)
{
return true;
}
}
return false;
}
If anyone has an idea of what I can do, please let me know.
Update:
The reason for this is because I am trying to parse a text file containing strings with Norwegian and Chinese words, such as a dictionary. I want to split a string into strings, one of which contains the Norwegian word, and the other in Chinese. This will later be inserted into the database. Example lines:
impulsiv 形 衝動 的
imøtegå 動 反對, 反駁
imøtekomme 動 符合
alkoholmisbruk (er) 名 濫用 酒精 (名 濫用 酒精 的 人)
alkoholpåvirket 形 受 酒精 影響 的
breath test 名 呼吸 性 酒精 測試
alkymi (st) 名 煉金術 (名 煉金術 士)
all, alt, alle, 形 全部, 所有
, , - , , . isNorwegianChar , char, .
, æ, ø å , , .
:
$rFile = fopen("norsk-kinesisk.txt", "r");
$Count = 0;
while(!feof($rFile))
{
if(40== $Count)
{
break;
}
$sLine = fgets($rFile);
if(0 == $Count)
{
$sLine = mb_substr($sLine, 3);
}
$iLineLength = strlen($sLine);
$bChineseHasStarted = false;
$sNorwegianWord = '';
$sChineseWord = '';
for($iCount2 = 0; $iCount2 < $iLineLength; $iCount2++)
{
$char = mb_substr($sLine, $iCount2, 1);
if(($bChineseHasStarted === false) && (false == isNorwegianChar($char)))
{
$bChineseHasStarted = true;
}
if(false === $bChineseHasStarted)
{
$sNorwegianWord .= $char;
}
else
{
$sChineseWord .= $char;
}
}
$sNorwegianWord = trim($sNorwegianWord);
$sChineseWord = trim($sChineseWord);
$Count++;
}
fclose($rFile);