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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.