Validate the input text in PHP

0
24
PHP

This tutorial explains how to validate the input string in PHP.

Here we will create the function that removes the white spaces from the input string and remove all other script code to protect your database from SQL Injection.


function validate_text_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}

You can use this function anywhere to validate the input string.

LEAVE A REPLY

Please enter your comment!
Please enter your name here