Forum Moderators: coopster
First, the CMS (building page) starts a buffer
ob_start();
Then, it calls a function to pull all the variables ($VARS) I need for this particular page...
getPageVars($id);
Next, it runs through the functions the page needs to build using the $VARS array it just gathered...
HEADER($VARS);
CONTENT($VARS);
FOOTER($VARS);
When that is done, the CMS gathers the contents of the buffer and also stops the buffer...
$bufferContents = ob_get_contents();
ob_end_clean();
With the $bufferContents in hand, the CMS writes the contents to a file at a specified destination...
$filePath=fopen($destination,"w");
fwrite($filePath,$buffer);
fclose($filePath);
And all is well...
However... Due to the fact that all the PHP code gets processed when it goes into the buffer, I am unable to publish any pages that retain dynamic PHP code in them as a final product. In other words, I'd like to be able to use PHP code in the final .php pages written by the CMS... Any clever ideas how to accomplish this without dumping the whole buffer concept?
Thanks for reading my question!
then when it's time to extract:
$output = $buffered_file_retrieval;
$parts = explode('<!-- my_content -->',$output);
$mysubstitution = $whatever_processing_to_do;
$output = $parts[0] . $mysubstitution . $parts[1];
echo $output;
You could also use the str_replace() function:
$output = str_replace('<!-- my_content -->',$mysubstitution,$output);
which method to use would depend on the particulars/scope of the substitution.
Does this make any sense? It's kind of hard to detail in a generic way.
I imagine it's probably easier to manage if I make the substitution code an include() function. The include() function should work as normal once the modified buffer output is writen to the .php file. (right?)
With that solution in hand, know of any other methods to send php thru a buffer without processing?
Thanks again, appreciate your help!