How do you put a line in the body?
-
There's a line like "blabla," bla"... "bla," how to put it in the mass. Explode doesn't fit because of a variety of "blabla," fields can be
"name1","name2","name3","name4" "name1",,,"name4" "nam,dcd,e1",,,"name4" "na\"me1",,,"name4"
-
Why not?
explode()
?Cut the first and last roll in the line, and then, with help.
explode()
Share the entire divider","
♪$str = '"blabla,","","bla" ... "bla"'; $array = explode('","', substr($str, 1, strlen($str) - 2)); print_r($array);
UPD:I've got a simple washing machine:
<?php
$line = '"na"me1",,,"name4","nam,dcd,e1",,,"name4"';
$ind = 0;
$arr = array();
$arr[$ind] = $line{0};
$in_str = ($line{0} == '"');
// посимвольный обход всей строки
for( $i = 1; $i < strlen($line); $i++ ){
// переход в режима в кавычках или за кавычками
if( ($line{$i} == '"') && ($line{$i - 1} != '\') ){
$in_str = !$in_str;
}
// если нашли разделитель за кавычками, то заполняем следующий элемент массива
if( ($line{$i} == ',') && !$in_str ){
$arr[++$ind] = '';
}else{
$arr[$ind] .= $line{$i};
}
}
print_r($arr);