PDA

View Full Version : Splitting up a template file...?



TheSpaceDude
May 1st, 2001, 11:37
In PHP, how would I go about opening a file (that part I can do :-), putting everything above a certain line (eg. {content}) into the variable $header, and everything below the line into the variable $footer?

Don't think it would be too hard to do... but I cant figure out a way :\

Thanks in advance for the help :-)

lucifer
May 2nd, 2001, 11:43
$fileinfo=file("myfile"); # sets up array of lines

$header="";
$footer="";
$found=false;

for($i=0;$i<count($fileinfo);$i++){
if ($fileinfo[$i]=="{content}\n"){
$found=true;
} else {
if ($found){
$footer .= $fileinfo[$i];
} else {
$header .= $fileinfo[$i];
}
}
}




should work - will only work if the {content} line has nothing else in it plus you'll get loads of \n in the variables but you can chop them