I know there is a way of having a premade layout and put ##areaname## and get php to substitute for live content I have no idea how to do this please can someone help?
tpl files
Look at the replacement functions, like str_replace, etc. Maybe this is an idea...
$content=fopen('somefile', 'r');
$template="<br><font=red><b><u>My Replacement content</br>";
$template.="</u></b></font>";
$newcontent=str_replace("###header###", $template, $content);
I put that code in a php file changing somefile and get this returned
Resource id #1
any ideas?
Originally posted by dalecosp
$content=fopen('somefile', 'r'); $template="<br><font=red><b><u>My Replacement content</br>"; $template.="</u></b></font>"; $newcontent=str_replace("###header###", $template, $content);
[/B]
Well, here $content is the file pointer for "somefile" opened for reading. This should not be sent to str_replace, but rather the information. We need to add a separate line of code:
$contents = fread($content,filesize('somefile'));
Then we can use the str_replace:
$newcontent = str_replace("###header###",$template,$contents);
Hope that helps.
THANKS!!! it works just one more question, how do I make this work for multiple ##whatever##'s?
Sorry, LOL...can't open and then not read, kudos, Mordecai.
To use it multiple times, I'd make it into a function that accepts the parameters of ($somefile) where $somefile is your replacement content and ($thingy) where $thingy is whatever string you wish to replace---###HEADER### or ###CONTENT### or ###LINKBLOCK###, whatever.....
Sorry to sound n00bish but I aint got a clue how to do that
function replace($somefile, $thingy)
{
// Put the code here
}
I can get about as far as
<?
$content=fopen('layout.tpl', 'r');
$contents = fread($content,filesize('layout.tpl'));
$name="site name";
$lcontent="left content";
$content = "content";
$thingy = "##title##";
function replace($content, $thingy)
{
$newcontent=str_replace("$str", $template, $contents);
print $newcontent;
}
?>
then I get stuck on how to make it do two some exact code would be apreciated ty
try sth. like this:
<?php
$template_f = "tpl/footer.tpl";
$template_r = join(' ', file($template_f));
$charray = array(
"{http}" => $whatever,
"{top}" => $lala
);
$outvar .=strtr($template_r, $charray);
echo $outvar;
?>
replaces {var} with given content. good luck
Thanks! it works
sure