php
error_reporting(E_ALL & ~E_NOTICE);
$expression=$_GET['TrueTable']; //读取输入框数据
if(!empty($_GET['TrueTable'])){
$expression=strtoupper($expression); //将输入的小写字母,替代成大写字母
$expressionArr=str_split($expression); //将$expression转换成数组
foreach($expressionArr as $v){ //把字母放在 $varTotal数组中
if($v>='A' && $v){
$varTotal[]=$v;
}
}
$varTotal = array_unique($varTotal); //去掉$varTotal数组中重复的字母
sort($varTotal); //$varTotal数组中字母正向排序
$varTotal1 = preg_replace("/([A-Z])/","$\\1",$varTotal); //$varTotal1数组中字母变成变量
$maxN = count($varTotal);
//$expressionArr = preg_replace("/([A-Z])/","$\\1",$expressionArr); //$expressionArr数组中字母变成变量
$newExpression=implode('',$expressionArr); //$expressionArr数组变成字符串
//echo $newExpression."
";
$newExpression= preg_replace("/([A-Z])->([A-Z])/","!\\1|\\2",$newExpression);
$newExpression= preg_replace("/(\(.*?\))->([A-Z])/","!\\1|\\2",$newExpression);
$newExpression= preg_replace("/(\(.*?\))->(.*?)/","!\\1|\\2",$newExpression);
$newExpression= preg_replace("/([A-Z])->(.*?)/","!\\1|\\2",$newExpression);
$expressionArr=str_split($newExpression); //将$expression转换成数组
$expressionArr = preg_replace("/([A-Z])/","$\\1",$expressionArr);
$newExpression=implode('',$expressionArr);
//echo $newExpression;
}
?>
[ 说明:析取(|) , 合取(&) , 非(!) , 蕴含(->) , 等价(=) ]
{$v} | "; } echo "结果 | "; $result=pow(2,$maxN); for($i=0;$i$result;$i++){ $resultN[$i]=sprintf("%0{$maxN}d",decbin($i)); $resultN[$i]=str_split($resultN[$i]); } foreach($resultN as $k=>$v){ echo "
".$v1." | "; $varTotal2[$k1]=$varTotal1[$k1]."=".$v1; //echo $varTotal2[$k1]." "; eval($varTotal2[$k1].";"); } //echo $newExpression; eval("\$varTotal3[] = ".$newExpression.";"); foreach($varTotal3 as $k2=>$v){ if($v==NULL){ $varTotal3[$k2]=0; } } echo "".$varTotal3[$k]." | "; echo "