note 98624 added to function.require

From: Date: Sat, 26 Jun 2010 23:04:51 +0000
Subject: note 98624 added to function.require
Groups: php.notes 
Request: Send a blank email to php-notes+get-170497@lists.php.net to get a copy of this message
If you want to get a parsed PHP file, e.g file.php contains echo 'ciao'; the function below will return you the output of file.php that is ciao <?php // file and get, if you need to include a file.php?query_string. function pinclude($file, $type, $get = null) { $p = explode('/', $file); $file = end($p); $dir = ''; $n = count($p) - 1; for($i = 0; $i < $n; $i++) $dir .= $p[$i] . '/'; if($get !== null) { $tmp = $_GET; // back up $_GET = array(); $get = explode('&', $get); $n = count($get); for($i = 0; $i < $n; $i++) { if(strpos($get[$i], '=') === false) $_GET[$get[$i]] = 1; else { list($name, $val) = explode('=', $get[$i], 2); $_GET[$name] = $val; } } } ob_start(); chdir($dir); require $file; $out = ob_get_clean(); if($tmp) $_GET = $tmp; return $out; } $out = pinclude('./dir/yourfile.php', 'a=b&c=d&e'); echo $out; // i'm sorry but i forgot post requests... ?> ---- Server IP: 69.147.83.197 Probable Submitter: 93.43.232.226 ---- Manual Page -- http://www.php.net/manual/en/function.require.php Edit -- https://master.php.net/note/edit/98624 Del: integrated -- https://master.php.net/note/delete/98624/integrated Del: useless -- https://master.php.net/note/delete/98624/useless Del: bad code -- https://master.php.net/note/delete/98624/bad+code Del: spam -- https://master.php.net/note/delete/98624/spam Del: non-english -- https://master.php.net/note/delete/98624/non-english Del: in docs -- https://master.php.net/note/delete/98624/in+docs Del: other reasons-- https://master.php.net/note/delete/98624 Reject -- https://master.php.net/note/reject/98624 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#170497) next »