私はテンプレートクラスで作業しています。 私はそうのようなTPLファイル内の条件を行います:条件が偽であるとき私は@if('eee' == 'esee')
と@endif
を削除しますが、私は方法がわからない、すべての隠された仕事が、whan該当する
@if('eee' == 'esee')
<h2>Test</h2>
@endif
@if('aaa' == 'aaa')
<h2>Test</h2>
@endif
。私はコンテンツなしでタグを削除することができますどのようにここに
私の機能
private static function get_condition(){
$control = array();
preg_match_all('/@if\((?P<control>[^)]+)\)/', self::$viewMainContent, $control);
$matches = isset($control['control']) ? count($control['control']) : 0;
for($i = 0; $i < $matches; $i++) {
$operators = [' == ', ' != ', ' >= ', ' <= ', ' > ', ' < '];
foreach($operators as $operator){
if(preg_match('/'.$operator.'/', $control['control'][$i])){
$val = explode($operator, $control['control'][$i]);
$param = preg_grep('/\'[^"]*\'/is', $val, PREG_SET_ORDER);
$show = false;
if(count($param) == 2){
switch(trim($operator)){
case "==":
if($param[0] == $param[1]){ $show = true; }
break;
case "!=":
if($param[0] != $param[1]){ $show = true; }
break;
case ">=":
if($param[0] >= $param[1]){ $show = true; }
break;
case "<=":
if($param[0] <= $param[1]){ $show = true; }
break;
case ">":
if($param[0] > $param[1]){ $show = true; }
break;
case "<":
if($param[0] < $param[1]){ $show = true; }
break;
}
}
self::$viewMainContent = str_replace("\n", " ", self::$viewMainContent);
if(!$show){
self::$viewMainContent = preg_replace('/'.preg_quote($control[0][$i]).'(.*?)\@endif/', '', self::$viewMainContent);
} else {
//self::$viewMainContent = preg_replace('/'.preg_quote($control[0][$i]).'/', '', self::$viewMainContent);
//self::$viewMainContent = preg_replace('/@endif/', '', self::$viewMainContent);
}
}
}
}
}
?
Thxを
多分[strip_tags](http://php.net/manual/en/function.strip-tags.php)は助けることができます – bugwheels94
私はこれをどうしなければならないのか分かりません。私はtplで複数の条件があり、私は本当の条件からタグを削除したいだけです。 strip_tagsを使用すると、すべてのタグのみを削除できます。 または間違っていますか? – Neonlight