Код: Выделить всё
<?php
$version = 'v.2.0.2';
$reg = isset($_REQUEST['reg']) ? $_REQUEST['reg'] : '';
$txt = isset($_REQUEST['txt']) ? htmlspecialchars_decode($_REQUEST['txt']) : '';
$result = $out = false;
if(!empty($reg) && !empty($txt))
{ if(isset($_REQUEST['p1'])) $result = @preg_match_all($reg,$txt,$matches);
elseif(isset($_REQUEST['p2'])) $result = @preg_match_all($reg,$txt,$matches,PREG_OFFSET_CAPTURE);
elseif(isset($_REQUEST['p3'])) $result = @preg_match($reg,$txt,$matches);
elseif(isset($_REQUEST['p4'])) $result = @preg_match($reg,$txt,$matches,PREG_OFFSET_CAPTURE);
else $result = false;
$out = (($result) === false) ? "Ошибка..." : print_r($matches,true);
}
@header("Content-type: text/html; charset=utf-8;");
echo '<html>';
echo '<head>';
echo '<title>Тестировщик регулярных выражений PHP (Ваша версия ' . PHP_VERSION . ')</title>';
echo '</head>';
echo '<body leftMargin="0" topMargin="0" marginwidth="0" marginheight="0">';
echo '<div align="right"><i><small>Прототип: <a href="http://scriptumplus.ru/regtest/" target="_blank">scriptumplus.ru</a>, адаптировано для PHP: <a href="mailto:c61@yandex.ru" target=_blank">c61</a> ' . $version . '</small></i></div>';
echo '<form method="POST">';
echo '<input type="button" value="x" onclick="document.getElementById('."'reg').value=''; return false;".'"> ';
echo 'Регулярное выражение <a href="http://php.net/manual/ru/book.pcre.php" target="_blank">(Perl-совместимое)</a>:<br />';
echo '<textarea name="reg" id="reg" style="width:100%" rows=3>' . $reg . '</textarea>';
echo '<input type="button" value="x" onclick="document.getElementById('."'txt').value=''; return false;".'"> ';
echo 'Текст для проверки:<br />';
echo '<textarea name="txt" id="txt" style="width:100%" rows=13>' . htmlspecialchars($txt) . '</textarea>';
echo 'Выполнить: ';
echo '<input name="p1" type="submit" value="preg_match_all()"> ';
echo '<input name="p2" type="submit" value="preg_match_all()+позиции"> ';
echo '<input name="p3" type="submit" value="preg_match()"> ';
echo '<input name="p4" type="submit" value="preg_match()+позиции"> ';
echo '</form>';
echo 'Результат выполнения = ' . (($result === false) ? 'false' : $result) . ', массив совпадений:<br /><hr />';
echo '<pre id="pre">' . htmlspecialchars($out) . '</pre>';
echo '</body>';
echo '</html>';
?>
