Re: [PHP] Validating User Input

2002-04-19 Thread Danny Shepherd

Hi,

?php
function check_input($user_input, $min=0, $max=0, $text=false,
$number=false, $special=false, $default=)
{
$pattern=;
if ($text) $pattern.='a-zA-Z';
if ($number) $pattern.='0-9';
if ($special)
$pattern.='[:space:]\~\`\@\#\$\%\^\\*\(\)\_\+\-\=\\\{\}\|\:\\;\'\\\?\,\.
\/';

$regexp='^['.$pattern.']{'.$min.','.$max.'}$';

if (ereg($regexp,$user_input))
return $user_input;
else
return $default;
 }
?

That should take care of everything except the square brackets - not sure
how to go about getting them (escaping them didn't seem to work).

HTH

Danny.

- Original Message -
From: SP [EMAIL PROTECTED]
To: Php [EMAIL PROTECTED]
Sent: Friday, April 19, 2002 1:57 PM
Subject: [PHP] Validating User Input


 I am trying to validate an user's input.  I can get the ereg function to
 work if I just type in the pattern I'm searching for but my problem is I
 want to build the pattern through a variable first and then use that
 variable in the ereg function.

 For example, I want to check an input that's only text and only between 5
to
 20 characters in length.  Is this possible?

 function check_input($user_input, $min=0, $max=0, $text=false,
  $number=false, $special=false, $default=)
 {
   if ($text) $pattern .= a-zA-Z;
   if ($number) $pattern .= 0-9;
   if ($special) $pattern .= [:space:];

   if  (ereg(^[$pattern]{$min,$max}$, $user_input))
 return $user_input;
   else
 return $default;
 }

 Also, which of the following special characters is considered safe to
 accept?  I am just allowing spaces now but would like as many of the below
 characters to be included.

 ~ ` ! @ # $ % ^  * ( ) _ + - = [ ] \ { } | :  ; '   ? , . /


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Determine the difference between two dates

2002-04-19 Thread Danny Shepherd

use the date() command (http://www.php.net/date) - using $timeDiff as the
datestamp.

HTH

Danny

- Original Message -
From: Ron Allen [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Friday, April 19, 2002 2:56 PM
Subject: Re: [PHP] Determine the difference between two dates


 If I wanted to represent it in the format of Days,Hours,Minutes,Seconds
how
 would that work


 Danny Shepherd [EMAIL PROTECTED] wrote in message
 020e01c1e7a1$70098eb0$0200a8c0@dannys">news:020e01c1e7a1$70098eb0$0200a8c0@dannys...
  Firstly, I assume you mean Y-m-j H:i:s for the date format.
 
  To get the difference between 2 time strings :
 
  ?php
 
  // orginal time strings
  $firstTime=2002-04-19 13:49:00;
  $lastTime=2002-04-19 14:00:00;
 
  // convert to unix timestamps
  $firstTime=strtotime($firstTime);
  $lastTime=strtotime($lastTime);
 
  // perform subtraction to get the difference (in seconds) between times
  $timeDiff=$lastTime-$firstTime;
 
  //echo out the difference
  printf (Difference is %d seconds,$timeDiff);
 
  ?
 
  HTH
 
  Danny.
 
  - Original Message -
  From: Ron Allen [EMAIL PROTECTED]
  To: [EMAIL PROTECTED]
  Sent: Friday, April 19, 2002 1:08 PM
  Subject: [PHP] Determine the difference between two dates
 
 
   If I have two variables of time both in the format of Y-m-j J:i:s
   How would I go about and get the difference?
 
 



 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




<    1   2