3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Template { // Path var $path; // Handles var $handles = array(); // Vars var $v = array(); // Set templates path function, use relative, for explample: path('./html'); function SetPath ($path) { if (is_dir($path)) { $this->path = $path . '/'; return true; } else { die ('Template: path is not a relative path to an existent directory'); return false; } } // Loadfile Function; function LoadFile ($h) { if (empty($this->handles[$h])) { die ('Template: no filename specified for "'.$h.'"'); } $str = implode('', file($this->path.$this->handles[$h])); if (empty($str)) { die ('Template: template file ("'.$this->handles[$h].'") is empty'); } return $str; } // Set vars function, for exaple: setvars (array('onevar'=>'onevalue')); function SetVars ($arr) { while (list ($name, $value) = each ($arr)) { $this->v[0][$name] = $value; } return true; } // Set blockvars, for example: setbvars ('block.subblock', array('a'=>'b'); function SetBlockVars ($block, $arr) { if (strstr($block, '.')) { $all = explode ('.', $block); $count = count ($all) -1; $str = '$this->v[1]'; for ($i = 0; $i < $count; $i++) { $str .= '[\''.$all[$i].'\']'; eval ('$last = count ('.$str.') - 1;'); $str .= '['.$last.']'; } $str .= '[\''.$all[$count].'\'][] = $arr;'; eval ($str); } else { $this->v[1][$block][] = $arr; } return true; } // Set handles ( handle (array('name'=>'filename')) function Assign ($str) { $this->handles[$str] = $str.'.tpl'; return true; } // Compile code function compile ($code) { $code = str_replace ('\\', '\\\\', $code); $code = str_replace ('\'', '\\\'', $code); preg_match_all ('#\{([a-z0-9\-_.]+)\.([a-z0-9\-_]+)\}#is', $code, $bvars); $bvarscount = count ($bvars[0]); for ($i = 0; $i < $bvarscount; $i++) { $all = explode ('.', $bvars[1][$i]); $count = count ($all); $str = '$this->v[1]'; for ($ii = 0; $ii < $count; $ii++) { $str .= '[\''.$all[$ii].'\'][$_repeat_'.$all[$ii].']'; } $str .= '[\''.$bvars[2][$i].'\']'; $str = '\' . ( isset ('.$str.') ? '.$str.' : \'\' ) . \''; $replace[] = $str; $search[] = $bvars[0][$i]; } $code = str_replace ($search, $replace, $code); $code = preg_replace('#\{([a-z0-9\-_]*?)\}#is', '\' . ( ( isset($this->v[0][\'\1\']) ) ? $this->v[0][\'\1\'] : \'\' ) . \'', $code); $line = explode ("\n", $code); $lines = count ($line); $names = array (); for ($i = 0; $i < $lines; $i++) { $line[$i] = chop ($line[$i]); if (preg_match('#<!-- BEGIN (.*?) -->#', $line[$i], $temp)) { $blockname = $temp[1]; if (strstr ($blockname, '.')) { $blockarr = explode ('.', $blockname); $blocklen = count ($blockarr) -1; $ref = '$this->v[1]'; for ($x = 0; $x < $blocklen; $x++) { $ref .= '[\''.$blockarr[$x].'\'][$_repeat_'.$blockarr[$x].']'; } $ref .= '[\''.$blockarr[$x].'\']'; $line[$i] = '$_count_'.$blockarr[$x].' = ( isset ('.$ref.') ? count ('.$ref.') : 0);'; $line[$i] .= "\n".'for ($_repeat_'.$blockarr[$x].' = 0; $_repeat_'.$blockarr[$x].' < $_count_'.$blockarr[$x].'; $_repeat_'.$blockarr[$x].'++)'; $line[$i] .= "\n".'{ // BEGIN '.$blockname; } else { $ref = '$this->v[1][\''.$blockname.'\']'; $line[$i] = '$_count_'.$blockname.' = ( isset ('.$ref.') ? count ('.$ref.') : 0);'; $line[$i] .= "\n".'for ($_repeat_'.$blockname.' = 0; $_repeat_'.$blockname.' < $_count_'.$blockname.'; $_repeat_'.$blockname.'++)'; $line[$i] .= "\n".'{ // BEGIN '.$blockname; } } else if (preg_match('#<!-- END (.*?) -->#', $line[$i], $temp)) { $line[$i] = '} // END '.$temp[1]; } else { $line[$i] = 'print \''.$line[$i].'\'."\n";'; } } $code = implode ("\n", $line); return $code; } function Make ($handle) { $template = $this->LoadFile ($handle); $code = $this->compile ($template); eval ($code); /* highlight_string ("<?php\n".$code."\n?>"); */ return true; } } $tpl = new Template; $tpl->SetPath ('html/'); ?>
Output for git.master, git.master_jit, rfc.property-hooks
Warning: is_dir(): open_basedir restriction in effect. File(html/) is not within the allowed path(s): (/tmp:/in:/etc) in /in/ram1Z on line 13 Template: path is not a relative path to an existent directory

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
39.41 ms | 401 KiB | 8 Q