I've just raised a separate question on a problem with an enquiry form that had a deprecated eregi PHP function. Unfortunately, there's another file I missed that validates the form which is riddled with them :(
Here's the code below:
/* ERRORS */
function error($str) // private
{
$this->error = true;
$this->error_string .= $str;
}
/* VALIDATE FIELD AGAINST TYPE */
function checkit($value, $type) // private
{
$length = "";
if (eregi("^MIN[0-9]+$", $type)) {
$tmp = explode(":", $type);
$length = $tmp[1];
$type = "MINLENGTH";
}
if (eregi("^MAX[0-9]+$", $type)) {
$tmp = explode(":", $type);
$length = $tmp[1];
$type = "MAXLENGTH";
}
switch ($type) {
case "NOT_EMPTY":
$this->error_tmp = "string cannot be empty";
return $this->not_empty($value);
break;
case "MINLENGTH":
if (strlen($value) < $length) {
$this->error_tmp = "string to short";
return false;
} else {
return true;
}
break;
case "MAXLENGTH":
if (strlen($value) > $length) {
$this->error_tmp = "string to long";
return false;
} else {
return true;
}
break;
case "ALPHA":
$exp = "^[a-z]+$";
if ($this->not_empty($value) && eregi($exp, $value)) {
return true;
} else {
$this->error_tmp = "string not alpha";
return false;
}
break;
case "ALPHASPACE":
$exp = "^[a-z ]+$";
if ($this->not_empty($value) && eregi($exp, $value)) {
return true;
} else {
$this->error_tmp = "string not alphaspace";
return false;
}
break;
case "ALPHANUM":
$exp = "^[a-z0-9]+$";
if ($this->not_empty($value) && eregi($exp, $value)) {
return true;
} else {
$this->error_tmp = "string not alphanum";
return false;
}
break;
case "ALPHANUMSPACE":
$exp = "^[a-z0-9 ]+$";
if ($this->not_empty($value) && eregi($exp, $value)) {
return true;
} else {
$this->error_tmp = "string not alphanumspace";
return false;
}
break;
case "NUMERIC":
$exp = "^[0-9]+$";
if ($this->not_empty($value) && eregi($exp, $value)) {
return true;
} else {
$this->error_tmp = "string not numeric";
return false;
}
break;
case "NUMERICPLUS":
$exp = "^[0-9+-.]+$";
if ($this->not_empty($value) && eregi($exp, $value)) {
return true;
} else {
$this->error_tmp = "string not numericplus";
return false;
}
break;
case "EMAIL":
$exp = "^[A-Z0-9._%-]+#[A-Z0-9.-]+\.[A-Z]{2,4}$";
if ($this->not_empty($value) && eregi($exp, $value)) {
return true;
} else {
$this->error_tmp = "not a valid email";
return false;
}
break;
case "YYYYMMDD":
$exp = "^(19|20)[0-9][0-9][- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])$";
if ($this->not_empty($value) && eregi($exp, $value)) {
return true;
} else {
$this->error_tmp = "string not YYYYMMDD";
return false;
}
break;
case "DDMMYYYY":
$exp = "^(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)[0-9][0-9]$";
if ($this->not_empty($value) && eregi($exp, $value)) {
return true;
} else {
$this->error_tmp = "string not DDMMYYYY";
return false;
}
break;
case "MMDDYYYY":
$exp = "^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)[0-9][0-9]$";
if ($this->not_empty($value) && eregi($exp, $value)) {
return true;
} else {
$this->error_tmp = "string not MMDDYYYY";
return false;
}
break;
default:
if ($this->not_empty($value) && $this->regex($type, $value)) {
return true;
} else {
$this->error_tmp = "string not valid";
return false;
}
}
}
/* NOT_EMPTY */
function not_empty($value) // private
{
if (trim($value) == "") {
return false;
} else {
return true;
}
}
/* REGULAR EXPRESSION */
function regex($regex, $value) // private
{
$the_regex = 'ereg("' . $regex . '", "' . $value . '")';
$the_code = '<?php if(' . $the_regex . ') { return true; } else { return false; } ?>';
if (!eval('?>' . $the_code . '<?php ')) {
return false;
} else {
return true;
}
}
}
Are there too many to change?
I hope someone can help?
Thanks in advance, kind regards
Brian
Regex has the "case-insensitive" way to match a string. If you put the letter "i" at the end of the regular expression, the function preg_match() will match the string even if you are searching a lowercase sentence in an uppercase string.
In the case ALPHA, you can use this regular expression:
$exp = "/^[a-z]+$/i";
instead of
$exp = "^[a-z]+$";
Using this, you can change the PHP functions from eregi($exp, $value) to preg_match($exp, $value), which will return TRUE if there are matches.
You can read the related documentation of preg_match() function here: https://www.php.net/manual/en/function.preg-match.php
Andrea
Related
So In case if the user types in 1,000.00, this is a valid number. what if the user types in 1,0,000,00.0000,0
You see theres multiple errors in here where you a value cannot be 1,0... or 000,00 because it has to be at least 3 numbers after the comma. To further extend it, after the dot in a number you cannot have a comma.
$keyword = $_POST['keyword'];
if (preg_match('/0/',$keyword) ||preg_match('/1/',$keyword) ||preg_match('/2/',$keyword)||preg_match('/3/',$keyword) ||preg_match('/4/',$keyword) || preg_match('/5/',$keyword) || preg_match('/6/',$keyword) || preg_match('/7/',$keyword) ||preg_match('/8/',$keyword) ||preg_match('/9/',$keyword) ||preg_match('/-/',$keyword) ||preg_match('/+/',$keyword) || preg_match('/,/',$keyword) ) {
$keywordtest = $keyword;
if ($keyword[0] == '+' || $keyword[0] == '-')
{
$keywordtest = substr_replace($keyword, '1', 0, 1);
echo $keywordtest;
}
if (preg_match('/,/',$keyword))
{
$x = 0;
while(true)
{
$findme = ',';
$pos = strpos($keyword, $findme);
if ($pos !== false)
{
$posArray[x] = $pos;
$x = x + 1;
if (x == 10)
break;
}
}
$numberCheck = posArray[x-1];
if (is_numeric($numberCheck))
{
}
else
{
echo "false '{$keyword}' is not numeric", PHP_EOL;
return 0;
}
$numberCheck = posArray[x+1];
if (is_numeric($numberCheck))
{
}
else
{
echo "false '{$keyword}' is not numeric", PHP_EOL;
return 0;
}
$numberCheck = posArray[x+2];
if (is_numeric($numberCheck))
{
}
else
{
echo "false '{$keyword}' is not numeric", PHP_EOL;
return 0;
}
$numberCheck = posArray[x+3];
if (is_numeric($numberCheck))
{
}
else
{
echo "false '{$keyword}' is not numeric", PHP_EOL;
return 0;
}
}
test_numeric($keywordtest,$keyword);
return 0;
}
else
{
echo "false '{$keyword}' is not numeric", PHP_EOL;
}
function test_numeric($keywordtest,$keyword)
{
if (is_numeric($keywordtest)){
echo "true '{$keyword}' is numeric", PHP_EOL;
}
return 0;
}
?>
You will want to use filter_var in combination with the FILTER_VALIDATE_FLOAT filter type and the FILTER_FLAG_ALLOW_THOUSAND flag.
Then it is really straightforward:
// $val == 100000
$val = filter_var('100,000.00', FILTER_VALIDATE_FLOAT, array('flags' => FILTER_FLAG_ALLOW_THOUSAND));
// $val == -100000
$val = filter_var('-100,000.00', FILTER_VALIDATE_FLOAT, array('flags' => FILTER_FLAG_ALLOW_THOUSAND));
// $val === false (invalid)
$val = filter_var('100,000.00,00', FILTER_VALIDATE_FLOAT, array('flags' => FILTER_FLAG_ALLOW_THOUSAND));
I am using this whois class, it works fine on one server but it does not work properly on another server with the same PHP version 5.4, on first server it returns domain name status correctly, but on the other one it returns just one status: "domain name is not available" while the domain name is actually available.
<?
class Whois_domain {
var $possible_tlds;
var $whois_server;
var $free_string;
var $whois_param;
var $domain;
var $tld;
var $compl_domain;
var $full_info;
var $msg;
var $info;
var $os_system = "linux"; // switch between "linux" and "win"
function Whois_domain() {
$this->info = "";
$this->msg = "";
}
function process() {
if ($this->create_domain()) {
if ($this->full_info == "yes") {
$this->get_domain_info();
} else {
if ($this->check_only() == 1) {
$this->msg = "The domain name: <b>".$this->compl_domain."</b> is free.";
return true;
} elseif ($this->check_only() == 0) {
$this->msg = "The domain name: <b>".$this->compl_domain."</b> is not available";
return false;
} else {
$this->msg = "There was something wrong, try it again.";
}
}
} else {
$this->msg = "Only letters, numbers and hyphens (-) are valid!";
}
}
function check_entry() {
if (preg_match("/^([a-z0-9]+(\-?[a-z0-9]*)){2,63}$/i", $this->domain)) {
return true;
} else {
return false;
}
}
function create_tld_select() {
$menu = "<select name=\"tld\" style=\"margin-left:0;\">\n";
foreach ($this->possible_tlds as $val) {
$menu .= " <option value=\"".$val."\"";
$menu .= (isset($_POST['tld']) && $_POST['tld'] == $val) ? " selected=\"selected\">" : ">";
$menu .= $val."</option>\n";
}
$menu .= "</select>\n";
return $menu;
}
function create_domain() {
if ($this->check_entry()) {
$this->domain = strtolower($this->domain);
$this->compl_domain = $this->domain.".".$this->tld;
return true;
} else {
return false;
}
}
function check_only() {
$data = $this->get_whois_data();
if (is_array($data)) {
$found = 0;
foreach ($data as $val) {
if (eregi($this->free_string, $val)) {
$found = 1;
}
}
return $found;
} else {
$this->msg = "Error, please try it again.";
}
}
function get_domain_info() {
if ($this->create_domain()) {
$data = ($this->tld == "nl") ? $this->get_whois_data(true) : $this->get_whois_data();
if (is_array($data)) {
foreach ($data as $val) {
if (eregi($this->free_string, $val)) {
$this->msg = "The domain name: <b>".$this->compl_domain."</b> is free.";
$this->info = "";
break;
}
$this->info .= $val;
}
} else {
$this->msg = "Error, please try it again.";
}
} else {
$this->msg = "Only letters, numbers and hyphens (-) are valid!";
}
}
function get_whois_data($empty_param = false) {
// the parameter is new since version 1.20 and is used for .nl (dutch) domains only
if ($empty_param) {
$this->whois_param = "";
}
if ($this->tld == "de") $this->os_system = "win"; // this tld must be queried with fsock otherwise it will not work
if ($this->os_system == "win") {
$connection = #fsockopen($this->whois_server, 43);
if (!$connection) {
unset($connection);
$this->msg = "Can't connect to the server!";
return;
} else {
sleep(2);
fputs($connection, $this->whois_param.$this->compl_domain."\r\n");
while (!feof($connection)) {
$buffer[] = fgets($connection, 4096);
}
fclose($connection);
}
} else {
$string = "whois -h ".$this->whois_server." \"".$this->whois_param.$this->compl_domain."\"";
$string = str_replace (";", "", $string).";";
exec($string, $buffer);
}
if (isset($buffer)) {
//print_r($buffer);
return $buffer;
} else {
$this->msg = "Can't retrieve data from the server!";
}
}
}
?>
I changed files permissions and php versions on the other server, but still the same.
This has been solved, it was fsockopen restrictions on the server, it is fine now.
I'm newbie, and just want to asking about programming stuff. I hope you guys help me getting understand :)
which is more efficient in coding and performance between this two function?
first function using nested condition, and second function using simple condition,
which is better to be implemented?
function optionOne()
{
$a = getData();
$return = array();
if ($a === false) {
$return['error'] = true;
} else {
$b = getValue();
if ($b === false) {
$return['error'] = true;
} else {
$c = getVar();
if ($c === false) {
$return['error'] = true;
} else {
$return['error'] = false;
$return['message'] = 'congrat!';
}
}
}
return $return;
}
function optionTwo()
{
$return = array();
$a = getData();
if ($a === false) {
$return['error'] = true;
return $return;
}
$b = getValue();
if ($b === false) {
$return['error'] = true;
return $return;
}
$c = getVar();
if ($c === false) {
$return['error'] = true;
return $return;
} else {
$return['error'] = false;
$return['message'] = 'congrat!';
}
return $return;
}
thank you before guys,
function option()
{
$return=array();
$return['error'] = true;
switch(getData()){
case false:
return $return;
break;
case true:
if(getValue()==false){return $return;}
else{
if(getVar()==false){return $return;}
else{
$return['error'] = false;
$return['message'] = 'congrat!';}
}
break;
default:
return 'getData() return null value';
break;
}
}
i was tried to applied the switch method to your function, as one of your option too
A neater option would be to make the 3 functions throw an exception when there's an error instead of returning boolean false. That's what exceptions are for anyway. Then in your function you can just wrap the calls in a try-catch block.
function option {
$return = array();
try {
$a = getData();
$b = getValue();
$c = getVar();
$return['error'] = false;
$return['message'] = 'congrat!';
} catch(Exception e) {
$return['error'] = true;
}
return $return;
}
Using PHP write an anagram function? It should be handling different phrases and return boolean result.
Usage:
$pharse1 = 'ball';
$pharse2 = 'lbal';
if(is_anagram($pharse1,$pharse2)){
echo $pharse1 .' & '. $pharse2 . ' are anagram';
}else{
echo $pharse1 .' & '. $pharse2 . ' not anagram';
}
There's simpler way
function is_anagram($a, $b) {
return(count_chars($a, 1) == count_chars($b, 1));
}
example:
$a = 'argentino';
$b = 'ignorante';
echo is_anagram($a,$b); // output: 1
$a = 'batman';
$b = 'barman';
echo is_anagram($a,$b); // output (empty):
function is_anagram($pharse1,$pharse2){
$status = false;
if($pharse1 && $pharse2){
$pharse1=strtolower(str_replace(" ","", $pharse1));
$pharse2=strtolower(str_replace(" ","", $pharse2));
$pharse1 = str_split($pharse1);
$pharse2 = str_split($pharse2);
sort($pharse1);
sort($pharse2);
if($pharse1 === $pharse2){
$status = true;
}
}
return $status;
}
function check_anagram($str1, $str2) {
if (count_chars($str1, 1) == count_chars($str2, 1)) {
return "This '" . $str1 . "', '" . $str2 . "' are Anagram";
}
else {
return "This two strings are not anagram";
}
}
ECHO check_anagram('education', 'ducatione');
I don't see any answers which have addressed the fact that capital letters are different characters than lowercase to count_chars()
if (isAnagram('Polo','pool')) {
print "Is anagram";
} else {
print "This is not an anagram";
}
function isAnagram($string1, $string2)
{
// quick check, eliminate obvious mismatches quickly
if (strlen($string1) != strlen($string2)) {
return false;
}
// Handle uppercase to lowercase comparisons
$array1 = count_chars(strtolower($string1));
$array2 = count_chars(strtolower($string2));
// Check if
if (!empty(array_diff_assoc($array2, $array1))) {
return false;
}
if (!empty(array_diff_assoc($array1, $array2))) {
return false;
}
return true;
}
here is my variant :
public function is_anagram($wrd_1, $wrd_2)
{
$wrd_1 = str_split ( strtolower ( utf8_encode($wrd_1) ) );
$wrd_2 = str_split( strtolower ( utf8_encode($wrd_2) ) );
if ( count($wrd_1)!= count($wrd_2) ) return false;
if ( count( array_diff ( $wrd_1 ,$wrd_2) ) > 0 ) return false;
return true;
}
Heheh little large but work as well :)
public static function areStringsAnagrams($a, $b)
{
//throw new Exception('Waiting to be implemented.');
$a = str_split($a);
$test = array();
$compare = array();
foreach ($a as $key) {
if (!in_array($key, $test)) {
array_push($test, $key);
$compare[$key] = 1;
} else {
$compare[$key] += 1;
}
}
foreach ($compare as $key => $value) {
if ($value !== substr_count($b, $key)) {
return false;
}
}
return true;
}
This question already has answers here:
How to fix "Headers already sent" error in PHP
(11 answers)
Closed 9 years ago.
Does anyone see how headers could be sent in this script? I am using this script to validate a form. As a result it is causing headers to be sent so when I try to direct a user after implementing this script it causes the normal "Warning: Cannot modify header information - headers already sent" message. Here is the script:
<?php
class ValidatorObj
{
var $variable_name;
var $validator_string;
var $error_string;
}
/**
* Base class for custom validation objects
**/
class CustomValidator
{
function DoValidate(&$formars,&$error_hash)
{
return true;
}
}
/** Default error messages*/
define("E_VAL_REQUIRED_VALUE","Please enter the value for %s");
define("E_VAL_MAXLEN_EXCEEDED","Maximum length exceeded for %s.");
define("E_VAL_MINLEN_CHECK_FAILED","Please enter input with length more than %d for %s");
define("E_VAL_ALNUM_CHECK_FAILED","Please provide an alpha-numeric input for %s");
define("E_VAL_ALNUM_S_CHECK_FAILED","Please provide an alpha-numeric input for %s");
define("E_VAL_NUM_CHECK_FAILED","Please provide numeric input for %s");
define("E_VAL_ALPHA_CHECK_FAILED","Please provide alphabetic input for %s");
define("E_VAL_ALPHA_S_CHECK_FAILED","Please provide alphabetic input for %s");
define("E_VAL_EMAIL_CHECK_FAILED","Please provide a valida email address");
define("E_VAL_LESSTHAN_CHECK_FAILED","Enter a value less than %f for %s");
define("E_VAL_GREATERTHAN_CHECK_FAILED","Enter a value greater than %f for %s");
define("E_VAL_REGEXP_CHECK_FAILED","Please provide a valid input for %s");
define("E_VAL_DONTSEL_CHECK_FAILED","Wrong option selected for %s");
define("E_VAL_SELMIN_CHECK_FAILED","Please select minimum %d options for %s");
define("E_VAL_SELONE_CHECK_FAILED","Please select an option for %s");
define("E_VAL_EQELMNT_CHECK_FAILED","Value of %s should be same as that of %s");
define("E_VAL_NEELMNT_CHECK_FAILED","Value of %s should not be same as that of %s");
class FormValidator
{
var $validator_array;
var $error_hash;
var $custom_validators;
function FormValidator()
{
$this->validator_array = array();
$this->error_hash = array();
$this->custom_validators=array();
}
function AddCustomValidator(&$customv)
{
array_push($this->custom_validators,$customv);
}
function addValidation($variable,$validator,$error)
{
$validator_obj = new ValidatorObj();
$validator_obj->variable_name = $variable;
$validator_obj->validator_string = $validator;
$validator_obj->error_string = $error;
array_push($this->validator_array,$validator_obj);
}
function GetErrors()
{
return $this->error_hash;
}
function ValidateForm()
{
$bret = true;
$error_string="";
$error_to_display = "";
if(strcmp($_SERVER['REQUEST_METHOD'],'POST')==0)
{
$form_variables = $_POST;
}
else
{
$form_variables = $_GET;
}
$vcount = count($this->validator_array);
foreach($this->validator_array as $val_obj)
{
if(!$this->ValidateObject($val_obj,$form_variables,$error_string))
{
$bret = false;
$this->error_hash[$val_obj->variable_name] = $error_string;
}
}
if(true == $bret && count($this->custom_validators) > 0)
{
foreach( $this->custom_validators as $custom_val)
{
if(false == $custom_val->DoValidate($form_variables,$this->error_hash))
{
$bret = false;
}
}
}
return $bret;
}
function ValidateObject($validatorobj,$formvariables,&$error_string)
{
$bret = true;
$splitted = explode("=",$validatorobj->validator_string);
$command = $splitted[0];
$command_value = '';
if(isset($splitted[1]) && strlen($splitted[1])>0)
{
$command_value = $splitted[1];
}
$default_error_message="";
$input_value ="";
if(isset($formvariables[$validatorobj->variable_name]))
{
$input_value = $formvariables[$validatorobj->variable_name];
}
$bret = $this->ValidateCommand($command,$command_value,$input_value,
$default_error_message,
$validatorobj->variable_name,
$formvariables);
if(false == $bret)
{
if(isset($validatorobj->error_string) &&
strlen($validatorobj->error_string)>0)
{
$error_string = $validatorobj->error_string;
}
else
{
$error_string = $default_error_message;
}
}//if
return $bret;
}
function validate_req($input_value, &$default_error_message,$variable_name)
{
$bret = true;
if(!isset($input_value) ||
strlen($input_value) <=0)
{
$bret=false;
$default_error_message = sprintf(E_VAL_REQUIRED_VALUE,$variable_name);
}
return $bret;
}
function validate_maxlen($input_value,$max_len,$variable_name,&$default_error_message)
{
$bret = true;
if(isset($input_value) )
{
$input_length = strlen($input_value);
if($input_length > $max_len)
{
$bret=false;
$default_error_message = sprintf(E_VAL_MAXLEN_EXCEEDED,$variable_name);
}
}
return $bret;
}
function validate_minlen($input_value,$min_len,$variable_name,&$default_error_message)
{
$bret = true;
if(isset($input_value) )
{
$input_length = strlen($input_value);
if($input_length < $min_len)
{
$bret=false;
$default_error_message = sprintf(E_VAL_MINLEN_CHECK_FAILED,$min_len,$variable_name);
}
}
return $bret;
}
function test_datatype($input_value,$reg_exp)
{
if(ereg($reg_exp,$input_value))
{
return false;
}
return true;
}
function validate_email($email)
{
return eregi("^[_\.0-9a-zA-Z-]+#([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$", $email);
}
function validate_for_numeric_input($input_value,&$validation_success)
{
$more_validations=true;
$validation_success = true;
if(strlen($input_value)>0)
{
if(false == is_numeric($input_value))
{
$validation_success = false;
$more_validations=false;
}
}
else
{
$more_validations=false;
}
return $more_validations;
}
function validate_lessthan($command_value,$input_value,
$variable_name,&$default_error_message)
{
$bret = true;
if(false == $this->validate_for_numeric_input($input_value,
$bret))
{
return $bret;
}
if($bret)
{
$lessthan = doubleval($command_value);
$float_inputval = doubleval($input_value);
if($float_inputval >= $lessthan)
{
$default_error_message = sprintf(E_VAL_LESSTHAN_CHECK_FAILED,
$lessthan,
$variable_name);
$bret = false;
}//if
}
return $bret ;
}
function validate_greaterthan($command_value,$input_value,$variable_name,&$default_error_message)
{
$bret = true;
if(false == $this->validate_for_numeric_input($input_value,$bret))
{
return $bret;
}
if($bret)
{
$greaterthan = doubleval($command_value);
$float_inputval = doubleval($input_value);
if($float_inputval <= $greaterthan)
{
$default_error_message = sprintf(E_VAL_GREATERTHAN_CHECK_FAILED,
$greaterthan,
$variable_name);
$bret = false;
}//if
}
return $bret ;
}
function validate_select($input_value,$command_value,&$default_error_message,$variable_name)
{
$bret=false;
if(is_array($input_value))
{
foreach($input_value as $value)
{
if($value == $command_value)
{
$bret=true;
break;
}
}
}
else
{
if($command_value == $input_value)
{
$bret=true;
}
}
if(false == $bret)
{
$default_error_message = sprintf(E_VAL_SHOULD_SEL_CHECK_FAILED,
$command_value,$variable_name);
}
return $bret;
}
function validate_dontselect($input_value,$command_value,&$default_error_message,$variable_name)
{
$bret=true;
if(is_array($input_value))
{
foreach($input_value as $value)
{
if($value == $command_value)
{
$bret=false;
$default_error_message = sprintf(E_VAL_DONTSEL_CHECK_FAILED,$variable_name);
break;
}
}
}
else
{
if($command_value == $input_value)
{
$bret=false;
$default_error_message = sprintf(E_VAL_DONTSEL_CHECK_FAILED,$variable_name);
}
}
return $bret;
}
function ValidateCommand($command,$command_value,$input_value,&$default_error_message,$variable_name,$formvariables)
{
$bret=true;
switch($command)
{
case 'req':
{
$bret = $this->validate_req($input_value, $default_error_message,$variable_name);
break;
}
case 'maxlen':
{
$max_len = intval($command_value);
$bret = $this->validate_maxlen($input_value,$max_len,$variable_name,
$default_error_message);
break;
}
case 'minlen':
{
$min_len = intval($command_value);
$bret = $this->validate_minlen($input_value,$min_len,$variable_name,
$default_error_message);
break;
}
case 'alnum':
{
$bret= $this->test_datatype($input_value,"[^A-Za-z0-9]");
if(false == $bret)
{
$default_error_message = sprintf(E_VAL_ALNUM_CHECK_FAILED,$variable_name);
}
break;
}
case 'alnum_s':
{
$bret= $this->test_datatype($input_value,"[^A-Za-z0-9 ]");
if(false == $bret)
{
$default_error_message = sprintf(E_VAL_ALNUM_S_CHECK_FAILED,$variable_name);
}
break;
}
case 'num':
case 'numeric':
{
$bret= $this->test_datatype($input_value,"[^0-9]");
if(false == $bret)
{
$default_error_message = sprintf(E_VAL_NUM_CHECK_FAILED,$variable_name);
}
break;
}
case 'alpha':
{
$bret= $this->test_datatype($input_value,"[^A-Za-z]");
if(false == $bret)
{
$default_error_message = sprintf(E_VAL_ALPHA_CHECK_FAILED,$variable_name);
}
break;
}
case 'alpha_s':
{
$bret= $this->test_datatype($input_value,"[^A-Za-z ]");
if(false == $bret)
{
$default_error_message = sprintf(E_VAL_ALPHA_S_CHECK_FAILED,$variable_name);
}
break;
}
case 'email':
{
if(isset($input_value) && strlen($input_value)>0)
{
$bret= $this->validate_email($input_value);
if(false == $bret)
{
$default_error_message = E_VAL_EMAIL_CHECK_FAILED;
}
}
break;
}
case "lt":
case "lessthan":
{
$bret = $this->validate_lessthan($command_value,
$input_value,
$variable_name,
$default_error_message);
break;
}
case "gt":
case "greaterthan":
{
$bret = $this->validate_greaterthan($command_value,
$input_value,
$variable_name,
$default_error_message);
break;
}
case "regexp":
{
if(isset($input_value) && strlen($input_value)>0)
{
if(!preg_match("$command_value",$input_value))
{
$bret=false;
$default_error_message = sprintf(E_VAL_REGEXP_CHECK_FAILED,$variable_name);
}
}
break;
}
case "dontselect":
case "dontselectchk":
case "dontselectradio":
{
$bret = $this->validate_dontselect($input_value,
$command_value,
$default_error_message,
$variable_name);
break;
}//case
case "shouldselchk":
case "selectradio":
{
$bret = $this->validate_select($input_value,
$command_value,
$default_error_message,
$variable_name);
break;
}//case
case "selmin":
{
$min_count = intval($command_value);
if(isset($input_value))
{
if($min_count > 1)
{
$bret = (count($input_value) >= $min_count )?true:false;
}
else
{
$bret = true;
}
}
else
{
$bret= false;
$default_error_message = sprintf(E_VAL_SELMIN_CHECK_FAILED,$min_count,$variable_name);
}
break;
}//case
case "selone":
{
if(false == isset($input_value)||
strlen($input_value)<=0)
{
$bret= false;
$default_error_message = sprintf(E_VAL_SELONE_CHECK_FAILED,$variable_name);
}
break;
}
case "eqelmnt":
{
if(isset($formvariables[$command_value]) &&
strcmp($input_value,$formvariables[$command_value])==0 )
{
$bret=true;
}
else
{
$bret= false;
$default_error_message = sprintf(E_VAL_EQELMNT_CHECK_FAILED,$variable_name,$command_value);
}
break;
}
case "neelmnt":
{
if(isset($formvariables[$command_value]) &&
strcmp($input_value,$formvariables[$command_value]) !=0 )
{
$bret=true;
}
else
{
$bret= false;
$default_error_message = sprintf(E_VAL_NEELMNT_CHECK_FAILED,$variable_name,$command_value);
}
break;
}
}//switch
return $bret;
}//validdate command
}?>
after .the }?>
if you select all (Ctrl+A) you will see the white space proceeding the ?>
There is likely whitespace after the closing ?> tag. It's become quite common practice to leave off the ending ?> tag to prevent this exactly issue. But that can only be done in files that contain only code in classes, no procedural code.
To add on to RobertPitt, if your file is solely PHP only, add the <?php at the start, and remove the ?> to prevent careless whitespaces at the back.