@ 2013-11-14T14:40:34Z <?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];
echo $record;
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);
}
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 8.0.0 - 8.0.30 , 8.1.0 - 8.1.28 , 8.2.0 - 8.2.18 , 8.3.0 - 8.3.6 }o
Warning: Undefined array key "" in /in/2aPqb on line 42
]a]a]
Warning: Array to string conversion in /in/2aPqb on line 42
:u:u::u:B:u:BL:u:BLA:u:BLAB:u:BLABL:u:BLABLA:u:BLABLAB:u:BLABLABL:u:BLABLABLA:u:BLABLABLA :u:BLABLABLA {:u:BLABLABLA {{:u:BLABLABLA {{a:u:BLABLABLA {{a}}} Array} Output for 5.4.0 - 5.4.45 , 5.5.0 - 5.5.38 , 5.6.0 - 5.6.28 , 7.0.0 - 7.0.20 , 7.1.0 - 7.1.25 , 7.2.0 - 7.2.33 , 7.3.0 - 7.3.31 , 7.4.0 - 7.4.25 , 7.4.27 - 7.4.33 }o
Notice: Undefined index: in /in/2aPqb on line 42
]a]a]
Notice: Array to string conversion in /in/2aPqb on line 42
:u:u::u:B:u:BL:u:BLA:u:BLAB:u:BLABL:u:BLABLA:u:BLABLAB:u:BLABLABL:u:BLABLABLA:u:BLABLABLA :u:BLABLABLA {:u:BLABLABLA {{:u:BLABLABLA {{a:u:BLABLABLA {{a}}} Array} Output for 7.3.32 - 7.3.33 , 7.4.26 }o]a]a]:u:u::u:B:u:BL:u:BLA:u:BLAB:u:BLABL:u:BLABLA:u:BLABLAB:u:BLABLABL:u:BLABLABLA:u:BLABLABLA :u:BLABLABLA {:u:BLABLABLA {{:u:BLABLABLA {{a:u:BLABLABLA {{a}}} Array} Output for 5.3.0 - 5.3.29 }o
Notice: Undefined index: in /in/2aPqb on line 42
]a]a]:u:u::u:B:u:BL:u:BLA:u:BLAB:u:BLABL:u:BLABLA:u:BLABLAB:u:BLABLABL:u:BLABLABLA:u:BLABLABLA :u:BLABLABLA {:u:BLABLABLA {{:u:BLABLABLA {{a:u:BLABLABLA {{a}}} Array} Output for 4.3.0 - 4.3.11 , 4.4.0 - 4.4.9 , 5.0.0 - 5.0.5 , 5.1.0 - 5.1.6 , 5.2.0 - 5.2.17 }o
Notice: Undefined index: in /in/2aPqb on line 42
]a]a]:u:u::u:B:u:BL:u:BLA:u:BLAB:u:BLABL:u:BLABLA:u:BLABLAB:u:BLABLABL:u:BLABLABLA:u:BLABLABLA :u:BLABLABLA {:u:BLABLABLA {{:u:BLABLABLA {{a:u:BLABLABLA {{a}}} Array} preferences:dark mode live preview
292.09 ms | 403 KiB | 370 Q