<?php
if(isset($_GET['show_source'])) {
    
show_source(__FILE__);
    die();
}

//No automatic slash-or-quotes-behaviour I don't know about
if (get_magic_quotes_gpc()) {
   function 
stripslashes_deep($value)
   {
       
$value is_array($value) ?
                   
array_map('stripslashes_deep'$value) :
                   
stripslashes($value);

       return 
$value;
   }

   
$_REQUEST array_map('stripslashes_deep'$_REQUEST);
   
$_POST array_map('stripslashes_deep'$_POST);
   
$_GET array_map('stripslashes_deep'$_GET);
   
$_COOKIE array_map('stripslashes_deep'$_COOKIE);
}

if(!isset(
$_POST['match']))
    
$_POST['match'] = 'Enter your text here';

if(!isset(
$_POST['pattern']))
    
$_POST['pattern'] = '/(.)eR/i';

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>the Perl Compatible Regular Expression Tester</title>
</head>
<body style="font-family: Lucida Console; font-size: 10pt;">
<form method="post" action="index.php">
<table border="0" cellspacing="0" cellpadding="4" width="100%">
<tr><td style="width:408px;" valign="top"><b>Text to test:</b><br />
<textarea style="border: 1px solid black; width:400px; height:300px;" name="match" rows="20" cols="40"><?= htmlentities($_POST['match']); ?></textarea><br />
<b>Pattern:</b><br />
<textarea style="border: 1px solid black; width:400px; height:100px;" name="pattern" rows="10" cols="40"><?= htmlentities($_POST['pattern']); ?></textarea><br />
<div style="width:100%; text-align: right;"><input type="submit" value="Apply pattern &raquo;" /></div>
<br />
<b>Pattern as string (single quote-escaped):</b><br />
<textarea style="overflow-x: hidden; border: 1px solid black; width:400px; height:20px;" rows="2" cols="40"><?= htmlentities('\''.str_replace("'""\'"$_POST['pattern']).'\''); ?></textarea><br />
<b>Pattern as string (double quote-escaped):</b><br />
<textarea style="overflow-x: hidden; border: 1px solid black; width:400px; height:20px;" rows="2" cols="40"><?= htmlentities('"'.str_replace('"''\"'$_POST['pattern']).'"'); ?></textarea><br />
<br />
<p style="font-size: 7pt;">PCRE Tester by <a href="http://www.edesign.nl">eDesign.nl</a> | <a href="?show_source">src</a> | <a href="http://www.php.net/manual/en/regexp.reference.php">PCRE reference</a> | <a href="http://www.php.net/manual/en/reference.pcre.pattern.modifiers.php">PCRE modifiers</a> | <a href="http://www.php.net/manual/en/pcre.pattern.php">More on PCRE</a><br />
<br />
Perl, the only language that doesn't change when RSA encrypted</p>
<p>
    <a href="http://validator.w3.org/check?uri=http%3A%2F%2Fregex.edesign.nl%2F"><img
        src="http://www.w3.org/Icons/valid-xhtml10"
        alt="Valid XHTML 1.0 Strict" height="31" width="88" style="border: 0px;" /></a>
  </p></td> 
  <?
$matches 
= array();

$n preg_match_all($_POST['pattern'], $_POST['match'], $matches);
?><td valign="top" style="border-left: 1px solid black;"><div id="matched" style="width:100%"><b>Matches: <?= $n ?></b><br /><br /><?

 

$match_keys 
array_keys($matches);
for(
$i 0$max count($matches); $i $max$i++) {
    if(
$i == 0)
        echo 
'<b>Pattern: '.htmlentities($_POST['pattern']).'</b><br />';
    else
        echo 
'<b>Subpattern: '.$match_keys[$i].'</b><br />';
    for(
$j 0$j count($matches[$match_keys[$i]]); $j++)
        echo 
'Match '.$j.': '.htmlentities($matches[$match_keys[$i]][$j]).'<br />';
    echo 
'<br />';
}
?></div></td>
</tr>
</table>
</form>

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-11988604-1");
pageTracker._trackPageview();
} catch(err) {}</script>

</body>
</html>