This doesn't yet verify that named character entities are valid, however.
"/<\\/center *>/i" => '</span>'
);
$text = preg_replace( array_keys($fixtags), array_values($fixtags), $text );
- // another round, but without regex
- $fixtags = array(
- '& ' => '&',
- '&<' => '&<',
- );
- $text = str_replace( array_keys($fixtags), array_values($fixtags), $text );
+
+ # Clean up spare ampersands; note that we probably ought to be
+ # more careful about named entities.
+ $text = preg_replace(
+ '/&(?!:amp;|#[Xx][0-9A-fa-f]+;|#[0-9]+;|[a-zA-Z0-9]+;)/',
+ '&',
+ $text );
$text .= $this->categoryMagic () ;