Question

In: Computer Science

What does the following PHP code accomplish? 1. function validateInput ( $data ) { 2. $data...

What does the following PHP code accomplish?

1. function validateInput ( $data ) {

2. $data = trim ( $data );

3. $data = stripslashes ( $data );

4. $data = htmlspecialchars ($data , ENT_QUOTES | ENT_HTML5 ,'UTF -8 ');

5. return $data ;

6.   }

Solutions

Expert Solution


   Code Snippet:

       function validateInput ( $data ) {
           $data = trim ( $data );
           $data = stripslashes ( $data );
           $data = htmlspecialchars ($data , ENT_QUOTES | ENT_HTML5 ,'UTF -8 ');
           return $data ;
       }


   Explanation:
       The following function validates the string input and performs some operations.

       Like -
           trim ($data);       ->   It removes the backspace from the string $data and reassign it to $data.
           stripslashes($data)   ->   It removes the slashes from the string $data and reassign it to $data.
           htmlspecialchars($data , ENT_QUOTES | ENT_HTML5 ,'UTF-8');   ->   It convert special character to their HTML equivalent, example '>' will convert into <.

  
   Test string

       $data = " The\ number 5 > 3.";
      
       $data = trim ( $data );
       =>   $data = "The\ number 5 > 3."
      
       $data = stripslashes ( $data );
       =>   $data = "The number 5 > 3."

       $data = htmlspecialchars ($data , ENT_QUOTES | ENT_HTML5 ,'UTF -8 ');
       =>   $data = "The number 5 < 3."

       Final String $data = "The number 5 < 3."


Related Solutions

2) What does cooling mold temperatures accomplish?
2) What does cooling mold temperatures accomplish?
1. Why do we have depreciation recapture? What does depreciation recapture accomplish? 2. What is the...
1. Why do we have depreciation recapture? What does depreciation recapture accomplish? 2. What is the difference between 1245 recapture and 1250 recapture? Is there a different tax rate? 3. How would you report 1231 gain on a tax return? How would you report ordinary recapture?
How would I structure the following PHP (PDO) code into a table format using only PHP?...
How would I structure the following PHP (PDO) code into a table format using only PHP? //Our SQL statement, which will select a list of tables from the current MySQL database. $sql = "SELECT * FROM jobs"; //Prepare our SQL statement, $statement = $pdo->prepare($sql); //Execute the statement. $statement->execute(); //Fetch the rows from our statement. $tables = $statement->fetchAll(PDO::FETCH_NUM); //Loop through our table names. foreach($tables as $table){ //Print the table name out onto the page. echo $table[0], ' '; echo $table[1], '...
What is the FUNCTION (what it does, not what it is) of the following terms? 1.  ...
What is the FUNCTION (what it does, not what it is) of the following terms? 1.   Promoter – 2.   ORF – 3.   Compatible solute– 4.   Pasteurization – 5.   Bacteriostatic agent – 6.   Exposure of food to strong ionizing radiation– 7.   Fermentation of food – 8.   Glycolysis –
what does the polymerase chain reaction (PCR) accomplish? 1) PCR converts RNA to DNA 2) PCR...
what does the polymerase chain reaction (PCR) accomplish? 1) PCR converts RNA to DNA 2) PCR corrects mutation in a gene 3) PCR makes many copies of DNA segment 4) PCR joins short segments of DNA to make one long segment how does the ribosome select the next amino acid to add to a growing polypeptide chain? 1) the ribosome selects the amino acid that can form hydrogen bonds with the mRNA 2) the ribosome selects a tRNA that base-pairs...
PHP    1. Create a new PHP document (nit Objective 1)    2. Write a comment...
PHP    1. Create a new PHP document (nit Objective 1)    2. Write a comment similar to the following: "This is my first PHP document, which displays some data in the web browser"(Unit Objective 1)    3. Assign your name as a string value into the variable labeled myName (Unit Objective 2)    4. Assign 53870 numeric value into the variable named randomNumber (Unit Objective 2) 5. ssign the name of the web browser and operating system of the...
- Create an html form (bank form) and the PHP code with 2 accounts with options...
- Create an html form (bank form) and the PHP code with 2 accounts with options to transfer, deposit or withdraw money.
what is the calvin cycle? what does it accomplish? what is enzyme "start" it?
what is the calvin cycle? what does it accomplish? what is enzyme "start" it?
What are the values you get from "data[,1]" and "data[,2]" in r code? Are the values...
What are the values you get from "data[,1]" and "data[,2]" in r code? Are the values from "data[,1]" are the fitted values/ yhat values? When I try "fitted(data)" I get different values from "data[,1]", I am very confused.
Answer the following: 1- What is the function of the endocrine system and how does it...
Answer the following: 1- What is the function of the endocrine system and how does it work? 2- What is the difference between a psychologist and a psychiatrist? Discuss some of the issues that are diagnosed by either one. 3-Discuss about LBGTQ health issues, transgender medical issues not addressed by family medicine
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT