user1167910
user1167910

Reputation: 145

php split a string with comma

$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

Upvotes: 0

Views: 143

Answers (2)

Welling
Welling

Reputation: 556

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.

Upvotes: 0

Marc B
Marc B

Reputation: 360572

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.

Upvotes: 4

Related Questions