Was ist denn hiermit? Bin aber heute auch echt Blickfrei...
<pre><?
$sText = 'Der schnelle <span>[b]braune[/b] Fuchs [img][/img]springt <u>über</u></span> den faulen Hund ';
$p = xml_parser_create ();
xml_parser_set_option ($p , XML_OPTION_CASE_FOLDING , 0);
xml_parser_set_option ($p , XML_OPTION_SKIP_WHITE , 0);
xml_parse_into_struct ($p , '<root>'.$sText.'</root>' , $aVals);
$iLength = 36;
foreach ($aVals as $sKey => $aOptions)
{
if ($iLength > 0)
{
$aVals[$sKey]['value'] = substr (@ $aOptions['value'], 0 , $iLength);
$iLength = $iLength - strlen ($aVals[$sKey]['value']);
$sLastKey = $sKey;
continue;
}
unset ($aVals[$sKey]);
}
$aStack = array ();
reset ($aVals);
while (list ($sKey , $aOptions) = each ($aVals))
{
if ($aOptions['type']=='open') array_unshift ($aStack , $aOptions['tag']);
if ($aOptions['type']=='close') array_shift ($aStack);
if ($sKey == $sLastKey) break;
}
print_r($aVals);
print_r($aStack);