php,ctype_print不能处理$ _POST变量

So I'm new to php and I'm trying to do a simple input filter on my html form with ctype_print($_POST["commentContent"]) but it is not recognising illegal input. But when I use ctype_print($testCase) it is working. How can I do ctype_print() on a $_POST input value. What am I missing here?

My code: Html form:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>My Recipe Site</title>
    <link rel="stylesheet" type="text/css" href="mystyle.css"> 
  </head>
  <body>
    <h3>Comments:</h3>
    <form action="" method="POST">
      <textarea rows="10" cols="30" name="commentContent"></textarea>
      <br />
      <input type="submit" value="Post!">
      <br />
    </form>
  </body>
</html>

Here is the sample string i use in both $testcase and that i post to the form: "asdf \t"

Simple if php

$testCase = "asdf
\t";

if (ctype_print ( $_POST ["commentContent"] )) {
    echo "Great succes for: " . $_POST ["commentContent"];
} else {
    echo "DAMN, it dosent work: " . $_POST ["commentContent"];
}

echo "<br>";

if (ctype_alnum ( $testCase )) {
    echo "ctype on testcase works : " . $testCase;
} else {
    echo "ctype on testcase does not work : " .  $testCase;
}

Your code looks fine to me I think the main problem is, that you just type the characters into the comment box, so it is just text, you can test it with a simple file_put_contents(). If you type into the textarea the string asdf \t you will get a file with the content `asdf \t.

If you type in (for example) asdf≤ENTER><ENTER> you will get a file with the content:

asdf
// newline
// newline

So I think your code works.

<?php
$testCase = "asdf
\t";

file_put_contents( "test.txt", $_POST ["commentContent"] );
    if ( ctype_print( $_POST ["commentContent"] ) ) {
    echo "every character in text will actually create output: " . $_POST ["commentContent"];
} else {
    echo "text contains control characters or characters that do not have any output or control function at all: " . $_POST ["commentContent"];
}

echo "<br>";

if ( ctype_alnum( $testCase ) ) {
    echo "every character in text is either a letter or a digit: " . $testCase;
} else {
    echo "NOT EVERY character in text is either a letter or a digit: " . $testCase;
}
?>

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>My Recipe Site</title>
        <link rel="stylesheet" type="text/css" href="mystyle.css">
    </head>
    <body>
        <h3>Comments:</h3>
        <form action="" method="POST">
            <textarea rows="10" cols="30" name="commentContent"></textarea>
            <br />
            <input type="submit" value="Post!"> <br />     </form>

    </body>
</html>

UPDATED: changed the echo output to clarify. The echo output now gives back the method ( ctype_print(), ctype_alnum() ) description taken from the PHP DOCS for the cases true or false