I'm using this code to read any CSV file to build an array so that i can use it later, the problem I have is that this particular CSV file has columns with html
$csv = array_map('str_getcsv', file('docs/foo.csv'));
$headers = $csv[0];
unset($csv[0]);
$csvarray = [];
foreach ($csv as $row) {
$newRow = [];
foreach ($headers as $k => $key) {
$newRow[$key] = $row[$k];
}
$csvarray[] = $newRow;
}
it works fine with any other CSV file, but for this particular CSV it just doesn't work:
example csv:
cat,name,des,ldes,datas
1,foo1,desfoo1,<h1>foo</h1><p class="finetext">sometext</p>, data1,data2,data3
3,foo3,desfoo3,<h1>foo3</h1><p class="finetext">sometext</p>, data4,data6
the array I got is something like:
array (
[cat]=>1
[name]=>foo1
[des]=>desfoo1
[ldes]=>foo
... after this everything breaks...
So how can I build an array out this CSV file that has coulmns/values with html...
UPDATE
[1] => Array
(
[cat] => 12
[name] => Foo no html
[des] => From foo no html
[ldes] => 'Basic long desc with htmls
)
[2] => Array
(
[0] =>
)
[3] => Array
(
[0] =>
basic next row html
some text inside p with class
)
This is the array I'm getting, it just breaks down to a none sense array...