All pastes #590588 Raw Edit

Miscellany

public text v1 · immutable
#590588 ·published 2007-06-26 17:44 UTC
rendered paste body
<?php
class string_callback extends php_user_filter {
        private $data;
        private $bucket = null;
        private $func;
        function filter($in, $out, &$consumed, $closing) {
                while($bucket = stream_bucket_make_writeable($in)) {
                        $this->data .= $bucket->data;
                        $consumed += $bucket->datalen;
                        if($this->bucket === null)
                                $this->bucket = $bucket;
                }
                if($closing) {
                        $this->bucket->data = (string) call_user_func($this->func, $th$
                        $this->bucket->datalen = strlen($this->bucket->data);
                        stream_bucket_append($out, $this->bucket);
                        return PSFS_PASS_ON;
                }
                return PSFS_FEED_ME;
        }
        function onCreate() {
                $this->func = substr($this->filtername, 16);
                if(is_callable($this->func))
                        return true;
                return false;
        }

}

stream_filter_register("string.callback.*", "string_callback");

function short_tags_to_long_tags($in) {
        return preg_replace(array('@\<\?\s(.*?)\?\>@s', '@\<\?\=(.*?)\?\>@s'), array('<?php $1 ?>', '<?php echo $1 ?>'), $in);
}

include('php://filter/read=string.callback.short_tags_to_long_tags/resource=' . $theme_file);