Wednesday, October 24, 2007

Styles you can use with JavaScript

fontFamily
fontStyle
fontVariant
fontWeight
fontSize
font
color

background
backgroundColor
backgroundImage
backgroundRepeat
backgroundAttachment
backgroundPosition
backgroundPositionX
backgroundPositionY

wordSpacing
letterSpacing
textDecoration
textDecorationNone
textDecorationUnderline
textDecorationOverline
textDecorationLineThrough
textDecorationBlink

verticalAlign
textTransform
textAlign
textIndent
lineHeight

marginTop
marginRight
marginBottom
marginLeft
margin

paddingTop
paddingRight
paddingBottom
paddingLeft
padding

border
borderTop
borderRight
borderBottom
borderLeft
borderColor
borderTopColor
borderRightColor
borderBottomColor
borderLeftColor
borderWidth
borderTopWidth
borderRightWidth
borderBottomWidth
borderLeftWidth
borderStyle
borderTopStyle
borderRightStyle
borderBottomStyle
borderLeftStyle

width
height
styleFloat
clear
display
visibility

listStyleType
listStylePosition
listStyleImage
listStyle

whiteSpace
top
left
position
zIndex
overflow

pageBreakBefore
pageBreakAfter

cssText

pixelTop
pixelLeft
pixelWidth
pixelHeight

posTop
posLeft
posWidth
posHeight

cursor
clip
filter

Tuesday, October 23, 2007

Back link using JavaScript

Use the following in a(link) tag

a href="javascript:;" onClick="history.back();"

Wednesday, October 17, 2007

Regular Expression Online Tester

Here is a link where you can test your regular expressions.

Regular Expression Online Tester

http://www.quanetic.com/regex.php

Friday, October 5, 2007

To prevent yourself with sql injection, use mysql_real_escape_string

/* Quote variable to make safe
* Added on Aug 10, 2007 */
function quote_smart($value)
{
// Stripslashes because our get_magic_quotes_gpc is on
if(get_magic_quotes_gpc()) {
$value = stripslashes(trim($value));
} else {
$value = trim($value);
}

// Replaces empty string to NULL - what is the benefit of putting NULL value?
//if($value == '') $value = 'NULL';
// Real_escape_string
$value = "'" . mysql_real_escape_string($value) . "'";
return $value;
}

/* Quote Variable to make it safe - array */
function quote_smart_arr ($arr) {
foreach( $arr as $key => $list ) {
$list = & $arr[$key]; // Re-assign the variable
$this->quote_smart($list);
unset($list); // Break the link to the object so that foreach doesn't copy the next one on top of it.
}
}

Small if/else statements - ternary operator

echo "You have $i ". ($i==1 ? "message" : "messages"). " in your mailbox.\n";

How to use references in foreach safely and sanely in PHP 4

Reference Found: July 30, 2007

There are two really really important points to remember about foreach and references:

1. foreach makes a copy
2. references (and unset!) work by directly manipulating the symbol table

In practice, this means that if you have an array of objects (or arrays) and you need to work on them *in-place* in a foreach loop, you have to do this:

foreach( $object_list as $id => $the_object ) {
$the_object = & $object_list[$id]; // Re-assign the variable to point to the real object
....
unset($the_object); // Break the link to the object so that foreach doesn't copy the next one on top of it.
}

This really works. I have used it in dozens of places. Yes, you need it all, including the unset(). You will get extremely hard-to-find bugs if you leave out the unset().


- It was in my note, but I don't know where I found them.