reading unicode characters into a string
Posted: Thu Aug 07, 2008 2:39 am
hi friends,
I am having a csv (comma separated value) file , each character in the file is in unicode format. i.e [a 2 byte character per character].
csv data:
======
and,10
in,20
win,30
======
See the following code:
$file=fopen("testdata.csv","r");
$ch = fread($file,"2"); initial 2 bytes to be read for unicode format.
while(!feof($file))
{
$ch = fread($file,"2");
echo $ch; // displaying character from the file.
$str1="a";
if(strcasecmp($ch,$str1) == 0)
{
}else{
}
}
Here even if character 'a' is in the file the comparison always shows false.
It happens for any character in the file.
I am not getting what is the issue.
Is the format read from the file(unicode) and the string used in the php program
different or is there any encoding required to either of the format.
I am completely unaware of the encoding & how to detect .
I am a total new new bie to php
plz help me urgent.
Thanks,
himanshu k.
I am having a csv (comma separated value) file , each character in the file is in unicode format. i.e [a 2 byte character per character].
csv data:
======
and,10
in,20
win,30
======
See the following code:
$file=fopen("testdata.csv","r");
$ch = fread($file,"2"); initial 2 bytes to be read for unicode format.
while(!feof($file))
{
$ch = fread($file,"2");
echo $ch; // displaying character from the file.
$str1="a";
if(strcasecmp($ch,$str1) == 0)
{
}else{
}
}
Here even if character 'a' is in the file the comparison always shows false.
It happens for any character in the file.
I am not getting what is the issue.
Is the format read from the file(unicode) and the string used in the php program
different or is there any encoding required to either of the format.
I am completely unaware of the encoding & how to detect .
I am a total new new bie to php
plz help me urgent.
Thanks,
himanshu k.