[PHP] variable scope / preg_replace_callback question

2001-12-03 Thread Peter Bowyer

Hi,

Does anyone know of a way of passing other variables to the function being called by 
preg_replace_callback?  For instance, I have the following code:

function smarty_compile_lang($tpl_source) {
// en.php contains a very large array, $_lang
include_once '/home/test/en.php';
global $_lang;
return preg_replace_callback('/##(.+?)##/', '_compile_lang', $tpl_source);
}

function _compile_lang($key){
// If I include $_lang here then it gets
// loaded again and again - bad for performance as it is _very_ large
return $_lang[$key[1]];
} // End _compile_lang

Somehow I need to make $_lang global, or pass it through the function 
preg_replace_callback as an arguement for _compile_lang() - which I don't think is 
possible?

What can I do?  I've tried a global statement everywhere I can think of... and I don't 
want to include en.php outside the functions, as it'll be included then whether the 
templates are being compiled or not.  I'm 
guessing that I may want to look at a higher level of abstraction from these 
functions, as even if I have the include in the current place, it means that every 
time a template is compiled it gets reloaded (though that's 
not as bad as every time preg_replace_callback() finds something) whereas the best way 
would be to load it once per script invocation - and then only when the templates wer 
being compiled...

Suggestions?

TIA,
Peter.



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Re: [PEAR-DEV] Template class

2001-12-11 Thread Peter Bowyer

I think I've seen something like this before... hang on, isn't it called PHP???

Could you explain what advantages you see in doing it this way, as I can't 
see any :-(

Peter.

At 11:00 PM 12/10/01 +0100, Wolfram Kriesing wrote:
>(just in case any of the people on PEAR-DEV will read this at all,
>since everyone must be tired of the template class debates :-)  )
>
>i just wanted to say what i had to write, because i didnt see any of
>the existing template classes/engines provide me with that
>
>the main features are:
># compiling template class which (almost) only replaces '{' by and '}' by ?>, with pre and post filters
># uses indention to create the '{' and '}' for php-code inside the
>template, so clean code is a requirement and no closing tags like:
>{/if} are needed
># leaves all the power of php to you, not only the functionality the
>template engine implements
># nothing to learn, just use '{' and '}' instead of the php-tags in
>your template and indent your code properly
># the seperation of source and representation is all up to the
>programmer (either this is good or bad)
># provides some default filter
>
>
>a possible template
>-
>{if(sizeof($disadvantages))}
> {foreach($disadvantages as $aDisadvantage)}
> {$aDisadvantage}
>{else}
> no disadvantages registered yet :-)
>-
>
>the compiled code is nothing more than this
>-
>
> 
> 
>
> no disadvantages registered yet :-)
>
>-
>so you can see - easy to use, nothing to learn and should be fast :-)
>
>feel free to have a look at
> http://wolfram.kriesing.de/programming/
>
>
>
>PS: BTW what was the decision on a multiple classes in PEAR
>which do the same thing?
>
>--
>Wolfram
>
>--
>PEAR Development Mailing List (http://pear.php.net/)
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>To contact the list administrators, e-mail: [EMAIL PROTECTED]

--oOo--
Narrow Gauge on the web - photos, directory and forums!
http://www.narrow-gauge.co.uk
--oOo--
Peter's web page - Scottish narrow gauge in 009
http://members.aol.com/reywob/
--oOo--


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]