deotpit
1
Hi everyone,
My text file contains the following string: “ãéðä”.
My PHP batch to convert that string goes like this:
<?php
$text = iconv("UTF-8","ISO-8859-1", "ãéðä");
echo $text;
?>
When I run the code I get the converted text I want .
In a case i have more then one such string, I use the following code:
<?php
$myFile = 'test.txt';
$myHandle = fopen($myFile,'r');
$myText = fread($myHandle, filesize($myFile));
$ridComma = explode(',',$myText);
foreach($ridComma as $item)
{
$text = iconv("UTF-8","ISO-8859-1", $item);
}
fclose($myHandle);
?>
This time I get the following error:
With the same conversion function I get the conversion in one batch and an error in the other !
Could anyone explain me why?
Thanks !
echo $item inside your loop and figure out which input string it is that’s causing the issue.
deotpit
3
Thanks,
Echo shows this:
ãéðä
What’s the second line of your text file then?
The illegal character is not in $matches[1], but in $xml
Try
iconv($matches[1], ‘utf-8//TRANSLIT’, $xml);
And showing us the input string would be nice for a better answer.
deotpit
6
There is no second line. I try to convert the same string in 2 defferent methods.
The second method is good for a text file with more then one string.
system
Closed
8
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.