trim
get rid of space, \n and \r, etc
$login = trim($_POST[‘user_login’]);
trim
get rid of space, \n and \r, etc
$login = trim($_POST[‘user_login’]);
To define an Array
$prod = array(
“prod1” => array(“id”=>”prod001″,”date” => “111208”, “name”=>”aaa”);
“prod2” => array(“id”=>”prod002″,”date” => “111108”, “name”=>”bbb”);
“prod3 => array(“id”=>”prod003″,”date” => “111008”, “name”=>”ccc”);
);
To read values out
foreach($sval1 as $key2 => $val2){
if($key2==”id”) echo “ID: $val2[0]\n”;
}
}
foreach($data as $value){
echo $value.”\n”;
}
Push elements into Array
if [ -n “$1” ]; then
filename = $1;
else
filename = `date –date=’1 hour ago’ “+%Y-%m-%d.%H”`;
fi
Compare numbers with -gt -lt -ne -eq
Compare strings with = !=
When using [[ ]]
if [[ ${domain} = “lalife.net” ]];then
echo “correct”
fi
([ ] needs the variable to be inside of “”)
Match
if [[ ${domain} =~ “lalife.net” ]];then
echo “correct”
fi
([ ] doesn’t work with =~)
To geneate a file on windows from prompt
C:\Documents and Settings>fsutil file createnew testfile 1024000
Read by lines
$hd = fopen(“$file”, “r”);
if($hd){
while(!feof($hd)){
$line = fgets($hd);
}
}
fclose($hd);
Read the whole file in
$contents = fread($hd, filesize($file));
}
fclose($hd);
Read image in binary
echo “couldn’t open $img_path”;
die;
}
while (!feof($img)) {
$contents .= fread($img, 1024);
}
fclose($img);
###Header for image
header(“Cache-Control: public”);
if(eregi(“\.[jpg|jpeg]”,$file)){
header (“Content-type: image/jpg”);
header(“Content-Disposition: inline; filename=$file”);
#header(‘Content-Length: ‘ . filesize($img));
print $contents;
}