i am trying to make a static site generator which works with a great routing class.
if (php_sapi_name() === "cli") { foreach ($router->get() as $route) { $out = ob_get_contents(); call_user_func_array($route['function'], array()); ob_end_clean(); file_put_contents("./temp/" . $route['expression'] . ".html", $out); } }
So i am trying this I can see the compiled html code through terminal but file is empty. How can I save output of call_user_func_array() function?
Advertisement
Answer
See this example:
if (php_sapi_name() === "cli") { // Start output buffering here ob_start(); foreach ($router->get() as $route) { call_user_func_array($route['function'], array()); // get output of `$route['function']` to $out variable $out = ob_get_contents(); // clean buffer ob_clean(); file_put_contents("./temp/" . $route['expression'] . ".html", $out); } // stop output buffering ob_end_clean(); }