Regex resource

http://www.virtuosimedia.com/tutorials/37-tested-php-perl-and-javascript-regular-expressions

Posted on 1 Nov 2009, 18:26 - Category: Regex
No comments - Edit - Delete


Php array_map apply callback to all elements of an array, return the array as before

$_POST = array_map('trim',$_POST);

very nice

Posted on 1 Nov 2009, 17:03 - Category: Php
No comments - Edit - Delete


Perl file directory functions

open(LOG, ">>../../../../logs/logfile.txt") || Error('open','file');

# to lock the file while writing to it, until closed
flock(LOG, 2) || Error('lock', 'file'); # this way two users don't simultaneously mess things up... flock(LOG,1) would request shared access to the file (for reading)

print LOG "$comments\n";

my @logmessages = <LOG>; # read the entire file into an array (each line an element)
while <LOG> {
#do such and such $_; } read the file line by line only
}
close(LOG) || Error('close','file');

print "Content-type: text/html\n\n";
print "<p>You said: <em>$comments</em>\n";
print qq(<hr>would you like to see all the <a href="http://www.cookwood.com/cgi-bin/perl2e/files/readfromlog.cgi">messages?</a>);

sub Error {
print "Content-type: text/html\n\n";
print "The Server can't $_[0] the $_[1]: $! \n";
exit;
}

# rename a file
# also interesting date approach...
# this can also be used to move a file, new location determined by second filename provided of course, if file already there it's overwritten, also, old location file is obliterated
my($mday,$mon,$year) = (localtime)[3,4,5];
$mon += 1;
$year += 1900;
my $date=sprintf('%04d%02d%02d', $year, $mon, $mday);
my $filename = "logfile$date.txt"
rename("../../../../logs/logfile.txt","../../../../logs/$filename") || Error('rename','file');

# remove a file
unlink("../../../../logs/$filename") || Error('delete','file');

# check if file: exists, readable, writable, executable, etc.
# -e = exists
# -r = permissions are such that file can be read
# -x permissions are such that file can be executed
# -w file can be written to
# -d check if it's a directory
if(-e "../../../../logs/$fileman") { print qq(A log does exist); } else { print "Sorry, that log file doesn't exist"; }

# access a directory:
opendir(LOGDIR, "../../../../logs/") || Error('open','directory');
my @logfiles = readdir(LOGDIR);
closedir(LOGDIR);
if(@logfiles) { print "<p>You can choose from the following logs:<ul>"; foreach(sort @logfiles){ print "<li>$_" if/^logfile/; } print '</ul>'; }

# change the working directory
chdir("../../../../logs") || Error('change','directory');

# create a new directory
mkdir("public/arhives",0777) || Error('make','directory');

# change file or directory permissions
if(-e "public/archives"){
chmod(0777, "public/archives") || Error('change','permissions');
# this line is a good example of outputting something, anything to the browser to avoid a visible no output error!
print "<p>permissions have been changed";
}

# to remove/delete a directory (that's empty! otherwise delete everything IN it FIRST...)
rmdir("../archives") || Error('remove','directory');
print "removed";


Posted on 28 Oct 2009, 20:20 - Category: Perl
No comments - Edit - Delete


File Permissions Blurb

chmod(...blah blah

0oge:

zero
o = owner permissions number
g = owner's group's permissions number
e = everyone else's permissions

keywords: file, permissions, explorer

Posted on 7 Mar 2010, 24:37 - Category: Windows
No comments - Edit - Delete


Php php.ini location xampp

xampp/php/php.ini

not so!

xampp/apache/bin/php.ini
!!!!

Posted on 9 Nov 2009, 1:12 - Category: Php
No comments - Edit - Delete


Pages: ... [3] [4] [5] [6] [7] [8] ...
Loading