Regular expressions test code
| From: | B�rge Strand | Date: | Thu, 01 Jan 1970 00:00:00 +0000 |
| Subject: | Regular expressions test code | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-110885@lists.php.net to get a copy of this message | ||
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