I'm starting work on regular expressions in PHP these days. Just
thought I'd share my test code for others out there who are fresh
starters with the language and regular expressions.


file parser.php:
<?php
    // copyright Børge Strand
    // use this code as you feel like!

    print "<html>\n";
    print "<head>\n";
    print "<title>Testing regular expressions</title>\n";
    print "</head>\n";
    print "<body>\n";

    $string = $_REQUEST['string'];
    $pattern = $_REQUEST['pattern'];

    print '<form action="parser.php" method="POST">' . "\n";
    print 'STRING:<input name="string" value="' . $string . '" size="10"><br><br>' . 
"\n";
    print 'PATTERN:<input name="pattern" value="' . $pattern . '" size="10"><br><br>' 
. "\n";
    print '<input type="submit" value="OK"><br><br>' . "\n";
    print '</form>' . "\n";
    print 'preg_match("' . $pattern . '","' . $string . '") says: <br>' . "\n";

//    $pattern = "/^[a-z\-0-9]+_[a-z\-0-9]+_[0-9]+$/"; // example pattern
    if (preg_match($pattern, $string))
        print 'YES';
    else
        print 'NO';

    print "</body>\n";
    print "</html>\n"

?>


--
Børge

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to