| 
	
 | 
 Posted by Roman Ziak on 06/19/00 11:44 
Roman Ziak wrote: 
> 
> 	function ExpandMacros(path,macros) 
> 	{ 
> 	    text = get_file_content(path); 
> 
> 	    // expand'em - skipped 
> 
> 	    put_file_content(path.'.expanded', 
> 	        'define(\'EXPANDED\', 1);\n\n' . text); 
> 	} 
> 
> 	@include __FILE__.'.expanded" 
> 
> 	if(!EXPANDED) 
> 	{ 
> 	    ExpandMacros(__FILE__, array(/* macros definitions */) ) 
> 	    return; 
> 	} 
 
The above example is wrong and is a mixture of C and PHP. 
 
This one is working: 
 
<?php 
 
@include __FILE__.'.expanded'; 
 
if(1 != EXPANDED) 
{ 
	// this function should be elsewhere 
 
	function ExpandMacros($path) 
	{ 
		$text = file_get_contents($path); 
 
		// expand'em - skipped 
		$text = str_replace('MAX', '120', $text); 
 
		// strip expansion stub 
		$pos = strpos($text, '// ' . 'CODE BEGIN'); 
		$text = "<?php\n\ndefine('EXPANDED',1);\n\n" . substr($text, $pos); 
 
		file_put_contents($path.'.expanded',  $text); 
	} 
 
	ExpandMacros(__FILE__); 
 
	require __FILE__ . '.expanded'; 
 
	return; 
} 
 
// CODE BEGIN 
 
echo MAX; 
 
?>
 
  
Navigation:
[Reply to this message] 
 |