Username:   Password:  

Filter Analytics

// newClass for gaFilter extends sfFilter
class gaFilter extends sfFilter
{
  public function execute($filterChain)
  {
    // anything before action
    $filterChain->execute();
    // Find google code and check if current module is not disabled
    if(($gaCode = sfConfig::get("app_ga_code",false)) !== false
    && !in_array($this->getContext()->getModuleName(),sfConfig::get("app_ga_disabled_modules",array()))) {
      //RResponse with the tracker code.
      $response = $this->getContext()->getResponse();
      $response->setContent(str_ireplace('</body>', $gaCode.'</body>',$response->getContent())); 
    }
   }
}
 

Here's a filtered analytics code. <a href="http://www.asgames.net">Funny Games</a>

Tags

analytics php filter

Strip HTML tags and its contents

$dom = new DOMDocument();
$dom->loadHTML($string);
$dom->preserveWhiteSpace = false;
$spans = $dom->getElementsByTagName('span');
foreach($spans as $span) {
    $span->parentNode->removeChild($span);
}
echo $dom->saveHTML();
 

Removes <span>-Tags in HTML code and removes all span-Tags but keeps it's content.

Tags

HTML PHP span remove