如何在Elixir中更改命令提示符的颜色?

时间:2018-04-26 09:49:58

标签: elixir

例如我做

<?php
    if(isset($_POST['lrn']) && !empty($_POST['lrn'])) {
        include 'dbconn.php';

        $lrn = mysqli_real_escape_string($conn, $_POST['lrn']);
        $studentFname = mysqli_real_escape_string($conn, $_POST['studentFname']);
        $studentLname = mysqli_real_escape_string($conn, $_POST['studentLname']);
        $studentMname = mysqli_real_escape_string($conn, $_POST['studentMname']);
        $studentSname = mysqli_real_escape_string($conn, $_POST['studentSname']);
        $gender = mysqli_real_escape_string($conn, $_POST['gender']);
        $dob = mysqli_real_escape_string($conn, $_POST['dob']);
        $citizenship = mysqli_real_escape_string($conn, $_POST['citizenship']);
        $religion = mysqli_real_escape_string($conn, $_POST['religion']);
        $ethnicity = mysqli_real_escape_string($conn, $_POST['ethnicity']);
        $motherTongue = mysqli_real_escape_string($conn, $_POST['motherTongue']);
        $houseNum = mysqli_real_escape_string($conn, $_POST['houseNum']);
        $street = mysqli_real_escape_string($conn, $_POST['street']);
        $village = mysqli_real_escape_string($conn, $_POST['village']);
        $brgy = mysqli_real_escape_string($conn, $_POST['brgy']);
        $city = mysqli_real_escape_string($conn, $_POST['city']);
        $province = mysqli_real_escape_string($conn, $_POST['province']);
        $tel = mysqli_real_escape_string($conn, $_POST['tel']);
        $mobile = mysqli_real_escape_string($conn, $_POST['mobile']);
        $email = mysqli_real_escape_string($conn, $_POST['email']);
        $fatherName = mysqli_real_escape_string($conn, $_POST['fatherName']);
        $fatherNum = mysqli_real_escape_string($conn, $_POST['fatherNum']);
        $motherName = mysqli_real_escape_string($conn, $_POST['motherName']);
        $motherNum = mysqli_real_escape_string($conn, $_POST['motherNum']);
        $guardianName = mysqli_real_escape_string($conn, $_POST['guardianName']);
        $guardianNum = mysqli_real_escape_string($conn, $_POST['guardianNum']);
        $fileName = $_FILES['file']['name'];
        $fileTmpName = $_FILES['file']['tmp_name'];
        $fileSize = $_FILES['file']['size'];
        $fileError = $_FILES['file']['error'];
        $fileType = $_FILES['file']['type'];

        // File upload validation
        if(!empty($fileName)) {
            $fileExtn = explode(".", $fileName);
            $fileActualExtn = strtolower(end($fileExtn));

            $allowedType = array('jpg', 'jpeg', 'png', 'doc', 'docx', 'zip', 'rar', 'pdf');
            if(in_array($fileActualExtn, $allowedType)) {
                if($fileError == 0) {
                    if($fileSize < 10000) {
                        $fileNewName = uniqid('', true).".".$fileActualExtn;
                        $fileDestination = "../uploads/".$fileNewName;
                        move_uploaded_file($fileTmpName, $fileDestination);
                    } else {
                        echo "<p class='statusMsg red'><i class='fa fa-exclamation-triangle' aria-hidden='true'></i> Please upload a file that is less than 10mb!</p>";
                        exit();
                    }
                } else {
                    echo "<p class='statusMsg red'><i class='fa fa-exclamation-triangle' aria-hidden='true'></i> There was an error uploading your file, please try again!</p>";
                    exit();
                }
            } else {
                echo "<p class='statusMsg red'><i class='fa fa-exclamation-triangle' aria-hidden='true'></i> This file type is not allowed to upload!</p>";
                exit();
            }
        } else {
            $fileNewName = "";
        }

        $sql = "SELECT lrn FROM students";
        $result = mysqli_query($conn, $sql);
        $resultCount = mysqli_num_rows($result);
        if($resultCount > 0) {
            echo "<p class='statusMsg red'><i class='fa fa-exclamation-triangle' aria-hidden='true'></i> LRN was already in the database!</p>";
            exit();
        }

        // Date of Birth Validation
        function isRealDate($dob) { 
            if(false === strtotime($dob)) { 
                return false;
            }

            list($year, $month, $day) = explode('-', $dob); 
            return checkdate($month, $day, $year);
        }

        if(isRealDate($dob) != true) {
            echo "<p class='statusMsg red'><i class='fa fa-exclamation-triangle' aria-hidden='true'></i> Date of Birth is invalid!</p>";
            exit();
        }

        if(empty($lrn) || empty($studentFname) || empty($studentLname) || empty($studentMname) || empty($gender) || empty($dob) || empty($religion) || empty($houseNum) || empty($street) || empty($brgy) || empty($city) || empty($province) || empty($zip) || empty($mobile) || empty($email)) {
            echo "<p class='statusMsg red'><i class='fa fa-exclamation-triangle' aria-hidden='true'></i> Please fill out all required fields!</p>";
            exit();
        } elseif(empty($fatherName) && empty($motherName) && empty($guardianName)) {
            echo "<p class='statusMsg red'><i class='fa fa-exclamation-triangle' aria-hidden='true'></i> Provide atleast one of your guardian(s)!</p>";
            exit();
        } elseif(!is_numeric($lrn) || !is_numeric($tel) || !is_numeric($mobile) || !is_numeric($fatherNum) || !is_numeric($motherNum) || !is_numeric($guardianNum)) {
            echo "<p class='statusMsg red'><i class='fa fa-exclamation-triangle' aria-hidden='true'></i> Only numbers are allowed on this fields (LRN, Telephone No., Mobile No., Guardian's Contact No.)</p>";
            exit();
        } elseif(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
            echo "<p class='statusMsg red'><i class='fa fa-exclamation-triangle' aria-hidden='true'></i> Your email address is incorrect or invalid!</p>";
            exit();
        } else {
            // Get age
            $age = date_diff(date_create($dob), date_create('now'))->y;

            $studentFnameNew = ucwords(trim(preg_replace('!\s+!', ' ', $studentFname)));
            $studentLnameNew = ucwords(trim(preg_replace('!\s+!', ' ', $studentLname)));
            $studentMnameNew = ucwords(trim(preg_replace('!\s+!', ' ', $studentMname)));
            $studentSnameNew = ucwords(trim(preg_replace('!\s+!', ' ', $studentSname)));
            $citizenshipNew = ucwords(trim(preg_replace('!\s+!', ' ', $citizenship)));
            $religionNew = ucwords(trim(preg_replace('!\s+!', ' ', $religion)));
            $ethnicityNew = ucwords(trim(preg_replace('!\s+!', ' ', $ethnicity)));
            $motherTongueNew = ucwords(trim(preg_replace('!\s+!', ' ', $motherTongue)));
            $houseNumNew = ucwords(trim(preg_replace('!\s+!', ' ', $houseNum)));
            $streetNew = ucwords(trim(preg_replace('!\s+!', ' ', $street)));
            $villageNew = ucwords(trim(preg_replace('!\s+!', ' ', $village)));
            $brgyNew = ucwords(trim(preg_replace('!\s+!', ' ', $brgy)));
            $cityNew = ucwords(trim(preg_replace('!\s+!', ' ', $city)));
            $fatherNameNew = ucwords(trim(preg_replace('!\s+!', ' ', $fatherName)));
            $motherNameNew = ucwords(trim(preg_replace('!\s+!', ' ', $motherName)));
            $guardianNameNew = ucwords(trim(preg_replace('!\s+!', ' ', $guardianName)));
            $approvalStatus = 0;

            $sql = "INSERT INTO `students`(`lrn`, `student_firstname`, `student_lastname`, `student_middlename`, `student_suffixname`, `gender`, `dob`, `age`, `citizenship`, `religion`, `ethnic_group`, `mother_tongue`, `house_num`, `street`, `village`, `barangay`, `city`, `province`, `zip`, `tel`, `mobile`, `email`, `father_name`, `father_num`, `mother_name`, `mother_num`, `guardian_name`, `guardian_num`, `file`, `approval_status`) VALUES ('$lrn', '$studentFnameNew', '$studentLnameNew', '$studentMnameNew', '$studentSnameNew', '$gender', '$dob', '$age', '$citizenshipNew', '$religionNew', '$ethnicityNew', '$motherTongueNew', '$houseNumNew', '$streetNew', '$villageNew', '$brgyNew', '$cityNew', '$province', '$zip', '$tel', '$mobile', '$email', '$fatherNameNew', '$fatherNum', '$motherNameNew', '$motherNum', '$guardianNameNew', '$guardianNum', '$fileNewName', '$approvalStatus')";
            $result = mysqli_query($conn, $sql);
            echo "success";
        }
    }

我需要线条的背景为黄色,文字颜色为黑色。我怎么能这样做?

1 个答案:

答案 0 :(得分:5)

使用IO.ANSI中的功能可以更改文本或其背景的颜色。您可以定义自己的inspect函数,将背景更改为黄色,将文本更改为黑色,并打印检查的值:

defmodule A do
  def my_inspect(term) do
    IO.puts IO.ANSI.format([:yellow_background, :black, inspect(term)])
  end
end

A.my_inspect %{someprop: 123}

输出:

enter image description here