start('regex.tpl.html'); $out = ''; $repl = '[!MATCH!]'; if($HTTP_POST_VARS) { $found = 0; $rout = ''; $argarr = array(); //$p = stripslashes($HTTP_POST_VARS['pattern']); //$h = stripslashes($HTTP_POST_VARS['haystack']); $p = $_POST['pattern']; $h = $_POST['haystack']; //echo "
pat: $p\nhay: $h\n
"; if($HTTP_POST_VARS['rtype'] == 1) { $found = @preg_match($p,$h, $argarr); if($found) $rout = preg_replace($p,$repl,$h); } else { $found = @ereg($p,$h, $argarr); if($found) $rout = ereg_replace($p,$repl,$h); } $out .= ""; if($found) { $out .= "Pattern Match!

"; if($rout == $repl) $out .= '(the pattern matched entire haystack)'; else $out .= "

Here's where the pattern was found:

".disptag($rout); $numpsm = count($argarr); if($numpsm > 1) { $out .= "

Parenthesized substring matches:

'; } } else $out .= "Pattern Not Found"; $out .= "
"; } $ts = 40; if($wf->browser == 'netscape') $ts = 20; // if there are character codes in the input fields, they will get translated on display... if(strstr($p,'&')) $p = preg_replace('/&([a-z]{1,4});/','&\\1;',$p); if(strstr($h,'&')) $h = preg_replace('/&([a-z]{1,4});/','&\\1;',$h); // escape any single quotes so we don't break the input $p = str_replace("'","'",$p); $h = str_replace("'","'",$h); $out .= "
". "". "". "". "
Pattern:]+\.[a-zA-Z]{2,4})/')."' CLASS=info SIZE=$ts>
Haystack:
preg (PCRE) ereg (POSIX)
"; $wf->setAttrib("SHORT_INFO","Does it match?"); $wf->setAttrib("PAGE_HEADER","Regular Expression Tester"); $wf->setAttrib('MATCH', $repl); $wf->setAttrib("MAIN_CONTENT", $out); // assign some basic info to the template $wf->setAttribs($DISP_VARS); $wf->setAttrib('TITLE','Regular Expression Online Tester'); $wf->setAttrib('AUTHOR','Kurt Milligan'); $wf->setAttrib('KEYWORDS','php, chess, postgresql, html, acoustics, kurt, milligan, cindy, design'); $wf->setAttrib('DESCRIP',"Welcome to Quanetic.com, Kurt Milligan 's virtual sandbox for PHP and PostgreSQL, and place to spout off about things like chess, acoustics, and computers."); // parse and display $nb->process(); $wf->finish(); // clean up $wf->destroy(); $user->destroy(); $sess->destroy(); function disptag($in) { $out = ''; $out = str_replace('<','<',$in); $out = str_replace('>','>',$out); return $out; } ?>