Get Include Contents


/ Published in: PHP
Save to your folder(s)

This was posted on the PHP website, I use it quite often. You may get a warning as it is an "unsafe" include (include($var)), but it's a risk that needs to be taken.


Copy this code and paste it in your HTML
  1. /**
  2.  * Fetch the files contents -- parsed by PHP -- as if it were included
  3.  *
  4.  * @param string $file
  5.  * @return string
  6.  */
  7. function get_include_contents($file) {
  8. if (!is_file($file) || !file_exists($file) || !is_readable($file)) return false;
  9. include($file);
  10. $contents = ob_get_contents();
  11. return $contents;
  12. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.