iconv_substr problem

Topics: Developer Forum, User Forum
Nov 2, 2009 at 1:06 AM

Hi,   I tested export to excel and have problem as follows>

If export in UTF 8 string from mysql with strlen 1 (f.e. char A ), resp. chars ž , š....etc (strlen 2)

there is an error in php excel:

Notice: iconv_substr()..Unknown error (0)..../String.php on line 317

I think there is a problem with php iconv_substr function>

iconv_substr("A",0,1);
generates folowing error:
Notice: iconv_substr() [function.iconv-substr]: Unknown error (0) in [...]

Can you please help me best way hot to solve it?

i changed code in  function Substring

from>

$string = iconv_substr($pValue, $pStart, $pLength, 'UTF-8');

to>

$string=iconv("UTF-8","UTF-8",$pValue);

resp.

if (strlen($pValue)<=2) {
                $string=iconv("UTF-8","UTF-8",$pValue);
            } else {
                $string = iconv_substr($pValue, $pStart, $pLength, 'UTF-8');
            }

return $string;


Iam not sure it is good idea, can somebody help me what is the best way how to fix it?

Many thanks for help in advance

Peter

Developer
Nov 2, 2009 at 12:48 PM

Question 1:

Is it this bug?

http://bugs.php.net/bug.php?id=37773

Question 2:

What version of PHP are you using?

Question 3:

What do you when you run this:

var_dump(iconv('UTF-8', 'UTF-16LE', 'x'));

Nov 2, 2009 at 9:12 PM

Hi, how can I fix this problem under php 5.2.0 in php excel? , I think it is a.m. bug

http://bugs.php.net/bug.php?id=37773

Many thanks ahead for your help.

 

Developer
Nov 3, 2009 at 12:11 AM

Can you try to run the code from Question 3 above and say what you get?

Nov 3, 2009 at 12:37 PM

hi, here is the result       

string(2) "x�"

Developer
Nov 4, 2009 at 1:49 AM

I have made a change to detect whether iconv_substr is broken.

http://phpexcel.codeplex.com/WorkItem/View.aspx?WorkItemId=10876

Can you try with latest source code from here tomorrow:

http://phpexcel.codeplex.com/SourceControl/ListDownloadableCommits.aspx

Things should work if you have mbstring extension enabled in PHP. Can you check with phpinfo() that you have mbstring enabled?