html - w3schools did not explain this in PHP can someone explain it to me? -


hey guys learning php , w3schools not have listed purpose if these things. sorry not familiar names , conecepts well, hoping can kind go on me. searched youtube videos, not call correct name. "place "post in here because needs call have in html" $_post? variable? ect

        <form method="post" action="<?php echo htmlspecialchars($_server["php_self"]); ?>">             <!-- $_server["php_self"] super global variable returns filename of executing script.'             so, $_server["php_self"] sends submitted form data page itself,             instead of jumping different page. way, user error messages on same page form.-->             name: <input type="text" name="name"> <br>             e-mail: <input type="text" name="email"> <br>             website: <input type="text" name="website"> <br>              <input type="submit" value="send!">          </form>         <?php //        $name = $email = $website = "";          if ($_server["request_method"] == "post") {             echo ($_post["name"]);             echo ($_post["email"]);             echo ($_post['website']);         }  //        function test_input($data) { //            $data = trim($data); //            $data = stripslashes($data); //            $data = htmlspecialchars($data); //        }         ?> 

wondering in bottom trim, stripslashes, , why calling or whatever doing "htmlspecialchars" again if located in action""> line?

$_post reserved "superglobal" variable, meaning is:

  1. created automatically server ,
  2. available everywhere.

it automatically contains data sent server http post request. technically, (from manual):

an associative array of variables passed current script via http post method.

so if have form name , email input fields, $_post array keys named name , email, contain data submitted user. access these $_post['name'] , $_post['email'], respectively.

there several other superglobal variables, namely:

  • $globals
  • $_server
  • $_get
  • $_post
  • $_files
  • $_cookie
  • $_session
  • $_request
  • $_env

you can learn more reading the manual entry on $_post or the manual entry on superglobal variables.

to answer other questions:

trim() removes white space (like spaces, tabs, , new lines) beginning , end of string. example, trim(' foo ') produces foo without spaces. can make remove other characters. have xxxfooxxx. trim('xxxfooxxx', 'x') take away xs , leave foo.

stripslashes() removes slashes string has escaped characters. example (from manual):

$str = "is name o\'reilly?";  // outputs: name o'reilly? echo stripslashes($str); 

htmlspecialchars() turns special characters html "entities." specifically, changes following:

  • & (ampersand) becomes &amp;
  • " (double quote) becomes &quot; when ent_noquotes not set.
  • ' (single quote) becomes &#039; (or &apos;) when ent_quotes set.
  • < (less than) becomes &lt;
  • > (greater than) becomes &gt;

Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -