1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4. <head>
5. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
6. <title>Testing Regular Expression Patterns</title>
7. </head>
8. <body>
9. <?php // Script 13.1 - test_pattern.php
10. /* This script takes a submitted string and checks it against a submitted pattern. */
11.
12. // Set the variables to blank values:
13. $string = '';
14. $pattern = '';
15.
16. if ( isset($_POST['submitted'])) { // Has the form been submitted?
17.
18. // Assign values from the form:
19. $pattern = trim($_POST['pattern']);
20. $string = $_POST['string'];
21.
22. // Print the results:
23. print "<p>The result of checking<br /><span style=\"font-style: italic;\">$string</span><br />against<br /><span style=\"font-weight: bold;\">$pattern</span><br />is ";
24. if ( eregi($pattern, $string) ) {
25. print 'TRUE!</p>';
26. } else {
27. print 'FALSE!</p>';
28. }
29.
30. }
31. // Display the HTML form:
32. ?>
33. <form action="test_pattern.php" method="post">
34. <p>Regular Expression Pattern: <input type="text" name="pattern" value="<?php print $pattern; ?>" size="30" /></p>
35. <p>Test String: <input type="text" name="string" value="<?php print $string; ?>" size="30" /></p>
36. <input type="submit" name="submit" value="Test!" />
37. <input type="hidden" name="submitted" value="true" />
38. </form>
39. </body>
40. </html>