PHP version of the Truth-table-truevaluetable expression

Source: Internet
Author: User
Tags uppercase letter

Paste the code:

<?PHPerror_reporting(E_all& ~E_notice); $expression=$_get[' truetable '];//reading input box data    if(!Empty($_get[' Truetable '])){        $expression=Strtoupper($expression);//Replace the lowercase letter entered with an uppercase letter        $EXPRESSIONARR=Str_split($expression);//convert $expression to an array        foreach($EXPRESSIONARR  as $v){//Put the letters in the $varTotal array            if($v>= ' A ' &&$v<= ' Z '){                $varTotal[]=$v; }        }        $varTotal=Array_unique($varTotal);//remove repeated letters from the $vartotal array        Sort($varTotal);//alphabetical Ordering of $varTotal arrays        $varTotal 1=Preg_replace("/([A-z])/", "$\\1",$varTotal);//$varTotal 1 The letters in the array become variables        $maxN=Count($varTotal); //$EXPRESSIONARR = Preg_replace ("/([A-z])/", "$\\1", $EXPRESSIONARR);//$EXPRESSIONARR The letters in the array become variables        $newExpression=implode(‘‘,$EXPRESSIONARR);//$expressionArr array becomes a string//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);//convert $expression to an array        $EXPRESSIONARR=Preg_replace("/([A-z])/", "$\\1",$EXPRESSIONARR); $newExpression=implode(‘‘,$EXPRESSIONARR); //echo $newExpression;            }? ><! DOCTYPE html>$_get[' truetable ']?> "/> <input type=" Submit "value=" OK "/> <br/> <br/> &L t;!            --<input type= "reset" value= "Cancel"/><br/><br/> <input type= "button" value= "∨"/> <input type= "button" value= "∧"/> <input type= "button" value= "┐"/> <input type = "button" value= "→"/> <input type= "button" value= "↔"/><br/><br/>--> </for m> <!--[Description: Disjunction (∨), Hop (∧), non (┐), implication (→), equivalence (↔)]--> <p>[Description: Disjunction (|), collection (&), non (!), implication (- >), equivalent (=)]</p> <table width= "300px" style= "margin:30px auto 0 auto;text-align:center;border:1px s Olid #000; " > <?PHPEcho"<tr>"; if(!Empty($_get[' Truetable '])){                        foreach($varTotal  as $v){                            Echo"<td>{$v}</td> "; }                                            Echo"<td> Results </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 $k 1=$v 1){                                Echo"<td>".$v 1." </td> "; $varTotal 2[$k 1]=$varTotal 1[$k 1]." =".$v 1; //echo $varTotal 2[$k 1]. " ";                                Eval($varTotal 2[$k 1].";"); }                                                        //echo $newExpression;                            Eval("\ $varTotal 3[] =".$newExpression.";"); foreach($varTotal 3  as $k 2=$v){                                if($v==NULL){                                    $varTotal 3[$k 2]=0; }                                                        }                            Echo"<td>".$varTotal 3[$k]." </td> "; Echo"</tr>"; }                        //Print_r ($varTotal 3);                    }                                ?> </table> </div> </body>

PHP version of the Truth-table-truevaluetable expression

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.