Skip to content

Instantly share code, notes, and snippets.

@jmather
Created November 14, 2012 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmather/4074726 to your computer and use it in GitHub Desktop.
Save jmather/4074726 to your computer and use it in GitHub Desktop.
Filter bad rss unhappy characters out
<?php
class BadCharacterMungerFilter extends sfFilter
{
public function execute($filterChain)
{
$filterChain->execute();
// Execute this filter only once
if ($this->isFirstCall()) {
$response = $this->getContext()->getResponse();
$content = $response->getContent();
$bad_combos = array(
html_entity_decode('&#x2013;', ENT_COMPAT, 'UTF-8') => '&#x2013;',
html_entity_decode('&#8217;', ENT_COMPAT, 'UTF-8') => '&#2013;',
html_entity_decode('&#8220;', ENT_COMPAT, 'UTF-8') => '&#8220;',
html_entity_decode('&#8221;', ENT_COMPAT, 'UTF-8') => '&#8221;',
chr(226) . chr(128) . chr(153) => '\'',
chr(226) => '',
chr(128) => '',
chr(153) => '',
'&acirc;' => '&#8217;',
);
$content = str_replace(array_keys($bad_combos), array_values($bad_combos), $content);
$response->setContent($content);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment