3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php echo sqlTemplate("{{o}} {[a]} {{u:BLABLABLA {{a}} }}",array("o"=>"HELLO","a"=>array(1,323,452),"u"=>false)); function sqlTemplate($query,$vars){ /* $replace = function($matches) use ($vars) { $varName = trim($matches[2]); if(count($matches)==5){ return isset($vars[$varName])&&$$vars[$varName]?$this->sqlTemplate($matches[4],$vars):""; }else if($matches[1] == '['){ return implode(',',$vars[$varName]); }else if($matches[1] == '{'){ return $vars[$varName]; }else{ return $matches[0]; } };*/ $i = 0;$l = strlen($query)-4; $bigRecord = ""; while($i < $l){ if($query[$i] == '{' && ($query[$i+1] == '{' || $query[$i+1] == '[')){ $i+=2; $end = false; $level=0; $record = $query[$i-1]; while($i < $l){ $record .= $query[$i]; if($query[$i] == '{' && ($query[$i+1] == '{' || $query[$i+1] == '[')) $level++; if(($query[$i] == ']' || $query[$i] == '}') && $query[$i+1] == '}') $level--; if($level==-1){ if($record[0] == '['){ $bigRecord .= impode(',',$vars[trim(substr($record,1,-1))]); }else{ $pos = false; if($pos = strpos($record, ':') !== false){ $varName = trim(substr($record,1,$pos-1)); if(isset($vars[$varName]) && $vars[$varName]){ $bigRecord .= $sqlTemplate(substr($record,$pos,-1)); } }else{ $bigRecord .= $vars[trim(substr($record,1,-1))]; } } break; } $i++; } }else{ $bigRecord .= $query[$i]; } $i++; } return $bigRecord; //return preg_replace_callback('~\{([\[\{])([a-z0-9\_\-]+)(\:([^\}]*))?[\]\}]\}~i',$replace, $query); }
Output for 7.0.0 - 7.1.0
Fatal error: Uncaught Error: Call to undefined function impode() in /in/j4bf3:32 Stack trace: #0 /in/j4bf3(3): sqlTemplate('{{o}} {[a]} {{u...', Array) #1 {main} thrown in /in/j4bf3 on line 32
Process exited with code 255.
Output for hhvm-3.12.0
Fatal error: Uncaught Error: Call to undefined function impode() in /in/j4bf3:32 Stack trace: #0 /in/j4bf3(3): sqlTemplate() #1 {main}
Process exited with code 255.
Output for 5.0.0 - 5.6.28, hhvm-3.10.0
Fatal error: Call to undefined function impode() in /in/j4bf3 on line 32
Process exited with code 255.
Output for 4.4.5 - 4.4.9
Fatal error: Call to undefined function: impode() in /in/j4bf3 on line 32
Process exited with code 255.
Output for 4.3.2 - 4.4.4
Fatal error: Call to undefined function: impode() in /in/j4bf3 on line 32
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Call to undefined function: impode() in /in/j4bf3 on line 32