Merge chunk segments between tag delimiters.
function process_chunk($chunk) {
$processed = array();
$j = 0;
foreach ($chunk as $i => $piece) {
$next = isset($chunk[$i + 1]) ? $chunk[$i + 1] : NULL;
if (!isset($processed[$j])) {
$processed[$j] = '';
}
if (strpos($piece, '<') === 0 && drupal_substr($piece, drupal_strlen($piece) - 1) === '>') {
$processed[$j] = $piece;
$j++;
}
elseif (isset($next) && strpos($next, '<') === 0 && drupal_substr($next, drupal_strlen($next) - 1) === '>') {
$processed[$j] .= $piece;
$j++;
}
else {
$processed[$j] .= $piece;
}
}
return $processed;
}