Standard approach
Start by splitting your strings... Let's say you have:
$str = 'text, something, value; another, extra, thing; string, content, data';
Note: you can read the file with with file_get_contents.
Now you can use explode on it to get the parts:
$rows = explode(';', $str);
foreach ($rows as $row)
{
$cells = explode(',', $row);
//....
}
And output:
$rows = explode(';', $str);
foreach ($rows as $row)
{
echo '<tr>';
$cells = explode(',', $row);
foreach ($cells as $cell)
{
echo '<td>'.$cell.'</td>'
}
echo '</tr>';
echo "\n"; // just for presentation
}
That would yield:
<tr><td>text</td><td>something</td><td>value</td></tr>
<tr><td>another</td><td>extra<td><td>thing</td></tr>
<tr><td>string</td><td>content<td><td>data</td></tr>
str_getcsv
From PHP 5.3 and above you can do use str_getcsv:
$rows = str_getcsv($str, ';');
foreach ($rows as $row)
{
echo '<tr>';
$cells = str_getcsv(',', $row);
foreach ($cells as $cell)
{
echo '<td>'.$cell.'</td>'
}
echo '</tr>';
echo "\n"; // just for presentation
}
The adventage of using str_getcsv is that it allows you to specify eclosure and escape characters. For example:
$str = '"text", "something", "value"; "another", "look: \"escape sequence\"";
There the enclosure character is " and the escape character is \.
explodeto split the string, andforto loop over the resulting arrays.