Skip to content

Instantly share code, notes, and snippets.

@VaclavSir
Last active October 6, 2015 06:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VaclavSir/2952497 to your computer and use it in GitHub Desktop.
Save VaclavSir/2952497 to your computer and use it in GitHub Desktop.
PHP PCRE Tester
<?php
header('content-type: text/html; charset=utf-8');
$pattern = isset($_POST['pattern']) ? $_POST['pattern'] : '~^$~';
$subject = isset($_POST['subject']) ? $_POST['subject']: '';
?>
<h1>Preg_match tester</h1>
<form method="post">
<p>Pattern:<br><textarea name="pattern" cols="80" rows="4"><?php echo htmlspecialchars($pattern) ?></textarea></p>
<p>Subject:<br><textarea name="subject" cols="80" rows="4"><?php echo htmlspecialchars($subject) ?></textarea></p>
<p><input type="submit" value="Test"></p>
</form>
<?php
$result = preg_match($pattern, $subject, $matches);
?>
<h2>Result</h2>
<?php var_dump($result) ?>
<h2>Matches</h2>
<?php var_dump($matches) ?>
<h2>Input</h2>
<table border="1">
<tr>
<th>Pattern: </th>
<td><pre><?php echo htmlspecialchars($pattern) ?></pre></td>
</tr>
<tr>
<th>Subject: </th>
<td><pre><?php echo htmlspecialchars($subject) ?></pre></td>
</tr>
</table>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment