The followiing code:
<?php
$string = "test.html";
preg_match ("/^.*\.(.+)$/", $string, $arrMatches);
print_r ($arrMatches);
?>
Will produce the following output:
Array ( [0] => test.html [1] => html )
The first chracrater "/" signifies the beginning of the pattern.
The "" means the proceedding character(s) must be at the beginning of the string.
The "." means any character except a whitepace character. e.g space, newline
The "" means that there can be 0 or more of the preceeding character.
The "." is the literal period character. The backslash escapes it.
The "+" means one or more of the preceeding character.
The "$" character means the preceeding character(s) must be a the end of the string
The preg_match() function dumps an array into the third argument. This array contains the matched text from the expresion.
You may be thinking why an array. The reason being is that you can have sub expresions too. Each sub expresion is enclosed in brackets (.+) and if matched will also be added to the array.
The pattern can be editied to make the rules for a match more ight. e.g notr forward slash in file name.
for the documetnation visit the PHP site