Page 1 of 1

phil can you teach me.

Posted: Tue May 03, 2005 5:58 pm
by fernando
hi phil

i was looking at your function code.
and i found

Code: Select all

function getDiskPercent()
{
	$df = shell_exec( 'df '.ZM_DIR_EVENTS );
	$space = -1;
	if ( preg_match( '/\s(\d+)%/ms', $df, $matches ) )
		$space = $matches[1];
	return( $space );
}

function getDiskBlocks()
{
	$df = shell_exec( 'df '.ZM_DIR_EVENTS );
	$space = -1;
	if ( preg_match( '/\s(\d+)\s+\d+\s+\d+%/ms', $df, $matches ) )
		$space = $matches[1];
	return( $space );
}
i dont get the preg_match thing.. i look at the internet but just the basic description.
i cant figureit out what '/\s(\d+)\s+\d+\s+\d+%/ms' mean .. and how this can tell you the disk blocks using the "df" funcion.
can you tell me a good resouce to read..

Posted: Wed May 04, 2005 12:16 am
by zoneminder
These are perl regular expressions. It's a pretty standard format and typing 'perdoc perlre' on most Linux systems will get you the hard facts. However it's not a very friendly introduction. I'm sure you'll get something helpful (probably in Spanish) if you google for "regular expression tutorial" or something like that. If you're really stuck let me know and I'll see what I can find.

Essentially in the examples you gave though, \s is whitespace (space or tab) and \d is a numerical digit (0-9). Anything in parenthesis () will be captured and returned in the $matches array and a + just means there must be one or more of the preceding items, so \d+ means at least one digit, so 1 or 45 or 0974943 etc. The /ms bit at the end relates to how the expresion matches over multiple lines.

Phil

Posted: Wed May 04, 2005 12:39 am
by fernando
thanks phil
i get it a little more.
i found some more info like http://www.amk.ca/python/howto/regex/

but .. how you get the diskblock from df?
from this function i get 3199748
but how this number came from

Code: Select all

[root@localhost root]# df /var/www/html
Filesystem            Size  Used Avail Use% Mounted on
/dev/hda6             108G  3,1G  100G   3% /var

Posted: Wed May 04, 2005 1:19 am
by fernando
ok here a good tutorial
http://weblogtoolscollection.com/regex/regex.php

lots of examples.

then you can dowload editpad to practice. :)

thanks again phil