I use the wonderful Minify library for this.
http://code.google.com/p/minify/

I have the following bit of code before I render the template:

$post = new Vnl_FilterChain();
$post->add(new Minify_HTML());
$post->add(...other classes I may want to add here...);

$phptal->setPostFilter($post);

And the filter chain function is out there in the interwebs, coz I didn't
create it (thanks to someone here, I'm sure!):

class Vnl_FilterChain implements PHPTAL_Filter {
    private $_filters = array();

    public function add(PHPTAL_Filter $filter){
        $this->_filters[] = $filter;
    }

    public function filter($source){
        foreach($this->_filters as $filter){
            $source = $filter->filter($source);
        }
        return $source;
    }
}

The Vnl_ bit is just a naming convention of my own code. Ignore it.

So I suggest you implement something like that. It's got all the regex
goodness you could ever hope for, as far as shrinking HTML goes.

Cheers,

-Alister

---
Alister Cameron // Blogologist
http://www.alistercameron.com

Mob. 04 0404 5555
Fax 03 8610 0050

Click here to find me online:
http://clicktoadd.me/alicam


On Fri, Aug 14, 2009 at 11:24 PM, Richard Cernava <cern...@gmail.com> wrote:

> Marco Pivetta <ocram...@...> writes:
>
> >
> >
> > echo str_replace(array("\n","\r\n","
> ","\t"),"",$template->execute());What
> about this? :)
> > 2009/8/13 majk <hosema...@poczta.onet.pl> tab
> characters are replaced by ? characters in previous mails
> >
>
> I would think a pre-filter would be best, that way your not doing a replace
> each
> time you execute, but only once at template generation. Also, I think he
> wanted
> remove the front \t?
>
> class removeTabs implements PHPTAL_Filter {
>        public function filter($source){
>                return $source = preg_replace('/^\t+/m', '', $source);
>        }
> }
>
> $template->setPreFilter(new removeTabs());
>
>
> >
> >
> > _______________________________________________
> > PHPTAL mailing
> listphp...@lists.motion-twin.comhttp://
> lists.motion-twin.com/mailman/listinfo/phptal
> >
> >
> >
> >
> > -- Marco Pivetta - Ocramius AethrilStandard Ogame Project -
> StOgamehttp://www.stogame.netMaking Ogame a better place...
> >
> >
> > _______________________________________________
> > PHPTAL mailing list
> > php...@...
> > http://lists.motion-twin.com/mailman/listinfo/phptal
> >
>
>
>
>
>
> _______________________________________________
> PHPTAL mailing list
> PHPTAL@lists.motion-twin.com
> http://lists.motion-twin.com/mailman/listinfo/phptal
>



-- 
Alister Cameron
Managing Director
Cameron Creative Pty Ltd
www.cameroncreative.com

Creative, Strategic, Innovative... never boring!
_______________________________________________
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal

Reply via email to