Re: replacing variables in file

From: Date: Sat, 11 Aug 2001 13:23:00 +0000
Subject: Re: replacing variables in file
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-62256@lists.php.net to get a copy of this message
In article <007801c121de$828fc100$f28e883e@portable1>, roberts_paul@bigfoot.com (Paul Roberts) wrote: > in Perl I use template files and parse them through a regx to change say > $cat > to the value of in the variable, I would like to do the same in php 4 > > example > > #open template and replace title and story then save to a new file > open (TEMPLATE, "$template") or die "cannot open template please try > again"; > @template = <TEMPLATE>; > close TEMPLATE ; > foreach $item (@template) { > $item =~s/\$(\w+)/${$1}/g; > > } > #output data to browser > $|=1; > print "Content-type: text/html\n\n"; > print @template ; > exit; > } $template="/path/to/somefile.inc"; include($template); The variable substitution happens automatically (as long as $var occurs within proper PHP syntax, such as "<?php $myvar1 ?>"). Output to browser is also automatic. See <http://php.net/include> for more info. -- CC

« previous php.general (#62256) next »