in folgender kombination aus preg_match_all() und foreach() wird der foreach() part einmal zu oft durchlaufen, wobei beim letzten durchlauf alle felder leer sind. warum? welche abhilfe gibt es?
Code:
if ($row->textwriter) {
$pattern = '
/ # Delimiter
(?:(.*?))? # AGSzabo
(?:@(.*?))? # Dilandau
(?:\[(.*?)\])? # Andreas G. Szabo
(?:\{(.*?)\})? # München
(?:@(.*?))? # Dilandau zweite mögliche position
(?:\/(.*?))? # Schneidersitz
(?:\((.*?)\))? # was in den klammern ist
(?:,|$) # komma muss trennend vorhanden sein
/isx';
preg_match_all($pattern, $row->textwriter, $array, PREG_SET_ORDER);
$lincol = $linecolor;
echo '<tr class="',$linecolor,'"><td class="label">';
echo 'Text';
echo '</td><td>';
echo '<table class="inner" cellspacing="0" cellpadding="0"><tr class="innerheadrow">
<td>By</td><td>Text</td><td>Of</td><td>Realname</td><td>Origin</td>
</tr>';
################################
############ HIER ###############
################################
foreach($array as $line) {
$linecolor = switchcolor($linecolor);
echo '<tr class="',$linecolor,'">';
echo '<td>',$line[1],'';
if (!$line[2]) $line[2] = $line[5];
if ($line[2]) echo ', aka ',$line[2],'';
echo '</td>';
echo '<td>',$line[7],'</td>';
# gruppe(n)
if (!$line[6]) $line[6] = $row->gruppe;
$ind = 0;
$names = explode('&', $line[6]);
foreach($names as $name) {
if ($name) $names[$ind] = ''.$name.'';
$ind++;
}
$name = implode(', ', $names);
echo '<td>',$name,'</td>';
# Realname und Origin
if ($line[3]) $line[3] = "****";
echo '<td>',$line[3],'</td>';
echo '<td>',$line[4],'</td>';
echo '</tr>';
}
####################################
############### BIS HIER ############
####################################
echo '</table>';
echo '</td></tr>';
# restore previous state
$linecolor = switchcolor($lincol);
}

Kommentar