PHP Classes

File: Examples/common/validation-regex.php

Recommend this page to a friend!
  Classes of Christian Vigh   PHP Command Line Arguments Parser   Examples/common/validation-regex.php   Download  
File: Examples/common/validation-regex.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Command Line Arguments Parser
Parse and extract arguments from the command line
Author: By
Last change: Update of Examples/common/validation-regex.php
Date: 1 year ago
Size: 1,262 bytes
 

Contents

Class file image Download
<?php
   
/***
        This example demonstrates the usage of the "validation-regex" attribute.
        It defines two parameters :
        - string_value1, which accepts a value containing only lowercase letters
        - string_value2, which accepts a value starting with a letter, followed by any number
          of letters and digits
     ***/
   
require_once ( dirname ( __FILE__ ) . '/../examples.inc.php' ) ;

   
$definitions = <<<END
<command>
    <usage>
        This example demonstrates the usage of the "validation-regex" attribute.
        It defines two parameters :
        - string_value1, which accepts a value containing only lowercase letters
        - string_value2, which accepts a value starting with a letter, followed by any number
          of letters and digits
    </usage>

    <string name="string_value1, sv1" validation-regex="[a-z]+">
        A parameter that accepts values containing lowercase letters only.
    </string>

    <string name="string_value2, sv2" validation-regex="/[a-z][a-z0-9]*/ix">
        A parameter that accepts values containing letters and digits, and starting with a letter.
    </string>
</command>
END;

   
$cl = new CLParser ( $definitions ) ;
    echo
"Value of -string_value1 : {$cl -> string_value1}\n" ;
    echo
"Value of -string_value2 : {$cl -> string_value2}\n" ;