Tuesday, April 23, 2013

Function of erag and eragi and solution of deprecated warnings.

PHP Function ereg():

Syntax

int ereg(string pattern, string originalstring, [array regs]);

Definition and Usage

The ereg() function searches a string specified by string for a string specified by pattern, returning true if the pattern is found, and false otherwise. The search is case sensitive in regard to alphabetical characters.
The optional input parameter regs contains an array of all matched expressions that were grouped by parentheses in the regular expression.

Return Value

  • It returns true if the pattern is found, and false otherwise.

Example

Following is the piece of code, copy and paste this code into a file and verify the result.
";
}
else
{
   echo "Could not found a .com
";
}
$retval = ereg(("(\.)(com$)"), $email_id, $regs);
if( $retval == true )
{
   echo "Found a .com and reg = ". $regs[0];
}
else
{
   echo "Could not found a .com";
}
?>
This will produce following result
Found a .com
Found a .com and reg = .com


PHP Function eregi()

Syntax

int eregi(string pattern, string string, [array regs]);

Definition and Usage

The eregi() function searches throughout a string specified by pattern for a string specified by string. The search is not case sensitive. Eregi() can be particularly useful when checking the validity of strings, such as passwords.
The optional input parameter regs contains an array of all matched expressions that were grouped by parentheses in the regular expression.

Return Value

  • It returns true if the pattern is validated, and false otherwise.

Example

Following is the piece of code, copy and paste this code into a file and verify the result.

This will produce following result
Invalid password! Passwords must be from 8 - 10 chars


warnings and solutions:-

function ereg() is deprecated:

solution: ereg() is replace into preg_match and add "/" at start and end.
 otherwise use "~"
exp:-

 if (!preg_match("/^<([a-zA-Z1-9]{1,$maxElem}) *(.*)>$/", $p_tag, $reg)) return false;

eragi_replace into preg_replace.

otherwise simply call this function in your page :-

error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);

 


 

Monday, April 15, 2013

Format Date Fields Using MySQL DATE_FORMAT()

MySQL DATE_FORMAT() Example

DATE_FORMAT(NOW(),'%W, %M %e, %Y @ %h:%i %p')
#yields 'Sunday, September 20, 2008 @ 12:45 PM'

MySQL DATE_FORMAT() Letter Representations

SpecifierDescription
%aAbbreviated weekday name (Sun..Sat)
%bAbbreviated month name (Jan..Dec)
%cMonth, numeric (0..12)
%DDay of the month with English suffix (0th, 1st, 2nd, 3rd, …)
%dDay of the month, numeric (00..31)
%eDay of the month, numeric (0..31)
%fMicroseconds (000000..999999)
%HHour (00..23)
%hHour (01..12)
%IHour (01..12)
%iMinutes, numeric (00..59)
%jDay of year (001..366)
%kHour (0..23)
%lHour (1..12)
%MMonth name (January..December)
%mMonth, numeric (00..12)
%pAM or PM
%rTime, 12-hour (hh:mm:ss followed by AM or PM)
%SSeconds (00..59)
%sSeconds (00..59)
%TTime, 24-hour (hh:mm:ss)
%UWeek (00..53), where Sunday is the first day of the week
%uWeek (00..53), where Monday is the first day of the week
%VWeek (01..53), where Sunday is the first day of the week; used with %X
%vWeek (01..53), where Monday is the first day of the week; used with %x
%WWeekday name (Sunday..Saturday)
%wDay of the week (0=Sunday..6=Saturday)
%XYear for the week where Sunday is the first day of the week, numeric, four digits; used with %V
%xYear for the week, where Monday is the first day of the week, numeric, four digits; used with %v
%YYear, numeric, four digits
%yYear, numeric (two digits)
%%A literal “%” character
%xx, for any “x” not listed above

Thursday, April 11, 2013

Javascript Char Codes (Key Codes) - Cambia Research

Javascript Char Codes (Key Codes) - Cambia Rese
Key Code
backspace 8
tab 9
enter 13
shift 16
ctrl 17
alt 18
pause/break 19
caps lock 20
escape 27
page up 33
page down 34
end 35
home 36
left arrow 37
up arrow 38
right arrow 39
down arrow 40
insert 45
delete 46
0 48
1 49
2 50
3 51
4 52
5 53
6 54
7 55
8 56
9 57
a 65
b 66
c 67
d 68
 
Key Code
e 69
f 70
g 71
h 72
i 73
j 74
k 75
l 76
m 77
n 78
o 79
p 80
q 81
r 82
s 83
t 84
u 85
v 86
w 87
x 88
y 89
z 90
left window key 91
right window key 92
select key 93
numpad 0 96
numpad 1 97
numpad 2 98
numpad 3 99
numpad 4 100
numpad 5 101
numpad 6 102
numpad 7 103
 
Key Code
numpad 8 104
numpad 9 105
multiply 106
add 107
subtract 109
decimal point 110
divide 111
f1 112
f2 113
f3 114
f4 115
f5 116
f6 117
f7 118
f8 119
f9 120
f10 121
f11 122
f12 123
num lock 144
scroll lock 145
semi-colon 186
equal sign 187
comma 188
dash 189
period 190
forward slash 191
grave accent 192
open bracket 219
back slash 220
close braket 221
single quote 222     

arch

example of coding in javascript:

 
function isNumberKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57))
return false;

return true;
}

In html call like this function :  onkeypress="return isNumberKey(event);"