Line break in PHP with CSV

1

Hello, friends!

I have this CSV: AndthiscodeinPHP:

<?php//Createatablefromacsvfile$area=0;echo"<table class=\"table table-hover\">\n\n";
$f = fopen("horarios_modificados.csv", "r", ";");
while (($line = fgetcsv($f)) !== false) {
    if($area == 0) echo "<thead>\n";
    if($area == 1) echo "<tbody>\n";
    $row = $line[0];    // We need to get the actual row (it is the first element in a 1-element array)
    $cells = explode(";",$row);
    echo "<tr>\n";
    foreach ($cells as $cell) {
        echo "<td>" . htmlspecialchars($cell) . "</td>\n";
    }
    echo "</tr>\n";
    if($area == 0) echo "</thead>\n";
    $area++;
}
fclose($f);
echo "</tbody>\n";
echo "\n</table>\n";
?>

I would like the exclamation point "!" (already inserted in my CSV) was a code in PHP to give new line (line break) in the CSV when in php in the browser.

For now it looks like this:

Could you help me?

    
asked by anonymous 05.09.2017 / 20:23

1 answer

3

Looking quickly, I think this would suffice:

echo "<td>" . str_replace("!", "<br>", htmlspecialchars($cell)) . "</td>\n";
    
05.09.2017 / 20:28