Jump to content

[SOLVED] Please check this function


scottybwoy

Recommended Posts

This function is part of my template class...  (Yeah, yeah, I know the arguments.. But this is for uploading to a flat file site).

 

<?

function ReplaceStatic($tcontent, $static_data) {

foreach ($static_data as $k => $v) {
    	if (is_array($v)) {
    		$prefix = $k;

    		$rowbegin = "<!--%" . $prefix . "_ROWBEGIN%-->";
        		$row_b_len = strlen($rowbegin);
        		$startrow = strpos($tcontent, $rowbegin);

        		$rowend = "<!--%" . $prefix . "_ROWEND%-->";
        		$row_e_len = strlen($rowend);
        		$endrow = strpos($tcontent, $rowend) + $row_e_len;
        		$rowlen = $endrow - $startrow;
        		$row = substr($tcontent, $startrow, $rowlen);
        		$subrowlen = ($endrow - $row_e_len) - ($startrow + $row_b_len);
        		$row_content = substr($tcontent, $startrow + $row_b_len, $subrowlen);
        		$nrow_content = "$row_content\r\n";
        		$rowsyntax = "<!--%" . $prefix . "_ROW%-->";
        		foreach ($v as $nv) {
        			$rows .= str_replace($rowsyntax, $nv, $nrow_content);
        		}

        		$tcontent = str_replace($row, $rows, $tcontent);
        		unset($rows);

    	} else {
	    	$placeMat = "<!--%$k%-->";
	    	$tcontent = str_replace($placeMat, $v, $tcontent);
    	}
    }

    return $tcontent;
}
?>

 

Now the actual functionality works fine, however the returned $tcontent is repeated a number of times and when written to the file, comes out as so.  Can anyone see why?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/85334-solved-please-check-this-function/
Share on other sites

An example of the output can be found here : http://www.mri.co.uk/controllers/eSATA-4MCR.php

 

Bare in mind the header etc is not included it's just the content part of the page.

 

It's also worth noting that it is placing 8 $vars and 2 $arrays

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.