Skip to content

Instantly share code, notes, and snippets.

@artemsites
Created September 4, 2018 08:10
Show Gist options
  • Save artemsites/89e7990203e51e7ac4651defe26eb586 to your computer and use it in GitHub Desktop.
Save artemsites/89e7990203e51e7ac4651defe26eb586 to your computer and use it in GitHub Desktop.
Включение файла PHP в строку при помощи буферизации.
<?php
/**
* Использование буферизации вывода для включения файла PHP в строку.
* http://php.net/manual/ru/function.ob-start.php
* http://php.net/manual/ru/function.ob-get-clean.php
*/
$string = get_include_contents('somefile.php');
function get_include_contents($filename) {
if (is_file($filename)) {
ob_start();
include $filename;
return ob_get_clean();
}
return false;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment