<?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<='Z'){ $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."<br />"; $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; } ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>真值表查詢1.0 BY:小臻</title> </head> <body> <span>$_GET['TrueTable'] ?>"/> <input type="submit" value="確定"/> <br /> <br /> <!--<input type="reset" value="取消" /><br /><br /> <input type="button" value="∨" /> <input type="button" value="∧" /> <input type="button" value="┐" /> <input type="button" value="→" /> <input type="button" value="↔" /><br /><br />--> </form> <!--[ 說明:析取(∨) , 合取(∧) , 非(┐) , 蘊含(→) , 等價(↔) ]--> <p>[ 說明:析取(|) , 合取(&) , 非(!) , 蘊含(->) , 等價(=) ]</p> <table width="300px">php echo "<tr>"; if(!empty($_GET['TrueTable'])){ foreach($varTotal as $v){ echo "<td>{$v}</td>"; } echo "<td>結果</td>"; $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 "<tr>"; foreach($resultN[$k] as $k1=>$v1){ echo "<td>".$v1."</td>"; $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 "<td>".$varTotal3[$k]."</td>"; echo "</tr>"; } //print_r($varTotal3); } ?> </table> </div> </body> </html>