/ Published in: PHP
input your regexp expression and submit it. It will return the supplied text with the matched results highlighted. A sample regex pattern to submit would be:
[aqtrew] which would highlight all instances of the letters a,q,t,r,e, and w
[^a-zA-Z 0-9] which would highlight all the punctuation.
Essentially you are inputting everything between the //'s for your match.
Expand |
Embed | Plain Text
<?php class regExpTest { public $pattern = ""; public $text = ""; public $result = ""; public function __construct($request) { $this->pattern = "/(" . $request["regExp"] . ")/"; $this->text = $request["text"]; $this->highlightMatches(); } private function highlightMatches() { } } if ($_POST["text"] == "") { $text = "The quick brown fox, jumped over the lazy dog. Then it drank a 'foty', slapped a hoe, and went to sleep.\n\nIt's a sad story really, I mean, what did that hoe do to deserve such treatment? Who cares right?!"; } else { $text = $_POST["text"]; } $pattern = $_POST["regExp"]; if ($_SERVER["REQUEST_METHOD"] == "POST") { $regExpTest = new regExpTest($_POST); $result = $regExpTest->result; } else {} ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Reg Exp Tester</title> <style type="text/css"> <!-- .highlight { background-color: #66FFFF; } --> </style> </head> <body> <form method="post" action="regExpTest.php"> <table border="0" cellpadding="5" cellspacing="0"> <tr> <td width="70" align="left" valign="top">Pattern:</td> <td align="left" valign="top"><input name="regExp" type="text" id="regExp" size="80" maxlength="100" value="<?php echo $pattern; ?>" /></td> </tr> <tr> <td align="left" valign="top"> </td> <td align="left" valign="top"><label> <input type="submit" id="button" value="Submit" /> </label></td> </tr> <tr> <td align="left" valign="top">Text:</td> <td align="left" valign="top"><textarea name="text" id="text" cols="45" rows="10"><?php echo $text; ?></textarea></td> </tr> </table> </form> </body> </html>
You need to login to post a comment.
