Hi, I have a string in the following format:
"var1","var2","var3","|{cr}"bar1","bar2","bar3","|{cr} ..and so on
Now, I have a script that is meant to split this string into an array, each containing the var, so I can manipulate it and move on.
I have the following, but it doesnt seem to work properly, it works properly for the first "set" of variables (1 set is upto the "|{cr} part, {cr} by the way is a carrige return), and then just keeps printing the first set over and over. I'v looked at my script over and over and can't figure it out. It is included below:
$oldpos = 1;
for($i=0; $i < 2; $i++)
{
$pos = strpos($str, '|' . ord(13), $oldpos);
$length = $pos - $oldpos;
$fields = substr($str, $oldpos, $length);
$oldpos = $pos + 1;
$field = preg_split('/","/', $fields);
echo $field[0] . ", ";
echo $field[1] . ", ";
echo $field[2] . "<br> ";
}
$str is the string. Can anyone help me with why this doesnt work ๐