0
$line = "30,[CVS Core] server  dot cvsignore file should be considered by client (1GCC6MB),[email protected],expert,[email protected]";
list($bugId,$bugText,$dupId,$submitId,$submitExpert,$bugFixerId) = split(",", $line);
echo $bugId.",";
echo $submitId.",";
echo $submitExpert.",";
echo $bugFixerId.",";
echo $bugText;

Here's my php code but I don't know why it shows that Undefined offset: 5

and here's the result

30,expert,[email protected],,[CVS Core] server dot cvsignore file should be considered by client (1GCC6MB)

I don't know what happened.

Thanks

5
  • BTW, the PHP documentation says: This function has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged. Use explode(',', $line);! Commented Oct 8, 2013 at 18:56
  • see the double ,, one of those is empty Commented Oct 8, 2013 at 18:58
  • 1
    @ComFreek is right, you should explode for that. And using var_dump(explode(",", $line)); you will see that you only get five parts, but you are trying to list them to six variables. Commented Oct 8, 2013 at 18:58
  • the text doesn't have dupId Commented Oct 8, 2013 at 18:59
  • str_getcsv() perhaps? Commented Oct 8, 2013 at 19:10

2 Answers 2

4

You've got 4 commas in your string, meaning you'll get 5 values after the split() call, but are trying to assign the split results to 6 variables. That last one is causing the undefined offset warning. Elimiante the $bugFixerID from the list() and the warning should go away.

Sign up to request clarification or add additional context in comments.

Comments

0

In $line you have 5 comma separate values, but list() is expecting 6 values.

$line = "30,[CVS Core] server  dot cvsignore file should be considered by client (1GCC6MB),[email protected],expert,[email protected]";

list($bugId,$bugText,$dupId,$submitId,$submitExpert) = split(",", $line);

$bugFixerId should be removed or need to provide the $bugFixerId on $line.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.