i'm trying what you are telling me, but i'm stuck.
$str_value = "";
$read = fopen($file, "rb");
while(!feof($read)){
$str_value .= fread($read, filesize($file));
}
fclose($read);
// Get length of print text
$str_start = strpos($str_value, "<!-- start -->");
$str_finish = strpos($str_value, "<!-- end -->");
$str_length = $str_finish-$str_start;
$str_value = substr($str_value, $str_start, $str_length);
// problem is below i'm sure.
$arrfile = explode("\n",$str_value);
echo $arrfile;
foreach($arrfile as $line => $value){
//echo "Key: $line | Value: $value<br>";
if(strstr($value,"< ?")){
//echo "Begin";
$php_begin = strpos($value, "< ?php");
$php_end = strpos($value, "? >");
$php_exec = substr($value, $php_begin, $php_end-$php_begin);
echo $php_exec;
//echo "Done";
eval($php_exec);
}else{
echo $value;
}
}
// in the end i'd do this:
// echo $str_value;
My data looks like this (between <!-- start --> and <!-- end -->
<!-- start -->
<p><font class="yes">Before PHP code</font>
<?php
$var = "PHP code!";
echo $var;
echo "<p>";
?>
<p><font >After PHP code</font>
<!-- end -->
I do notice in my foreach loop that the <?php string is in one line and the end tag is in another line. that means that my conditional if() statement and the variables set would be wrong, since i'd have to go a few more lines in order to get the position of ?>
i'm close, but i can't get around that! 🙁