Esempio n. 1
0
/**
 * File for displaying php examples for teaching
 * purposes. To display six examples (or however many)
 * put in a directory, create examples named 
 * prefix01.suffix to prefix06.suffix, then 
 * edit the call to getMaximumExampleNumber() and 
 * getExampleName() below to match your prefix
 * and suffix.
 * 
 * Author: Peter Nore
 * Created: July 20, 2011
 **/
require 'handy.php';
$state = new PageState();
// get the number of examples in the current directory
$maxFnumber = getMaximumExampleNumber('.', 'map');
/**
 * Searches the given directory for files with names like
 * 'examplePrefix01.exampleSuffix, examplePrefix02.exampleSuffix'
 * etc. Default is "example01.php", "example02.php". Returns
 * the maximum example number for the given prefix and suffix
 * in the directory, and false if there is a problem reading the dir.
 */
function getMaximumExampleNumber($directory = '.', $examplePrefix = 'example', $exampleSuffix = 'php')
{
    $maxFnumber = 0;
    if ($handle = opendir($directory)) {
        while (false !== ($file = readdir($handle))) {
            if (preg_match("/.*" . $examplePrefix . "\\d\\d\\.{$exampleSuffix}/", $file)) {
                $num = intval(preg_replace("/.*" . $examplePrefix . "(\\d+).*{$exampleSuffix}/", "\\1", $file));
                $maxFnumber = max($num, $maxFnumber);
Esempio n. 2
0
/**
 * File for displaying php examples for teaching
 * purposes. To display six examples (or however many)
 * put in a directory, create examples named 
 * prefix01.suffix to prefix06.suffix, then 
 * edit the call to getMaximumExampleNumber() and 
 * getExampleName() below to match your prefix
 * and suffix.
 * 
 * Author: Peter Nore
 * Created: July 20, 2011
 **/
require 'handy.php';
$state = new PageState();
// get the number of examples in the current directory
$maxFnumber = getMaximumExampleNumber();
/**
 * Searches the given directory for files with names like
 * 'examplePrefix01.exampleSuffix, examplePrefix02.exampleSuffix'
 * etc. Default is "example01.php", "example02.php". Returns
 * the maximum example number for the given prefix and suffix
 * in the directory, and false if there is a problem reading the dir.
 */
function getMaximumExampleNumber($directory = '.', $examplePrefix = 'example', $exampleSuffix = 'php')
{
    $maxFnumber = 0;
    if ($handle = opendir($directory)) {
        while (false !== ($file = readdir($handle))) {
            if (preg_match("/.*" . $examplePrefix . "\\d\\d\\.{$exampleSuffix}/", $file)) {
                $num = intval(preg_replace("/.*" . $examplePrefix . "(\\d+).*{$exampleSuffix}/", "\\1", $file));
                $maxFnumber = max($num, $maxFnumber);