Welcome Guest [Log In] [Register]
Welcome to iPeer. We hope you enjoy your visit.


You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
Regex Tester
Topic Started: Apr 28 2009, 02:13 AM (382 Views)
iPeer
Theres a few bugs you should know about before using this script. First off you cannot use escapes, or special commands as the script insists on replacing all "\" with "\\" and "\\" with "\\\\" etc. I am currently trying to find a way around this, if you can help me, let me know!

It can probably be shortened, but hey, i'm a learner of PHP.

Demo: Working | Not Working

Code:
Code:
 
<?php
/* You may use this script however you see fit, you may also modify it to fit your needs (if you fix the replacement of backslashes, please let me kinow) All I ask is you leave the title code intact. */
echo '<title>PHP/mSL regex tester v1.0 - By iPeer</title><center><font size=\"1\">I am aware some of the regex tested in this (specially for the mSL mode) would work, yet this script says it will not, I am working on a fix! I am also aware that it does not like escapes (\,\e) very much<br>the script is based of and ereg() result, NOT preg_match</font><br><br>';
if (!$_GET['regex']) $regex = $_POST['regex'];
else $regex = $_GET['regex'];
if (!$_GET['text']) $text = $_POST['text'];
else $text = $_GET['text'];
if (!$_GET['mode']) $mode = $_POST['mode'];
else $mode = $_GET['mode'];

echo '<form name="form1" method="post" action="regtest.php">
Text: <input name="text" type="text" value="' . $text . '" size="100" /><br />
Regex: <input name="regex" type="text" value="' . $regex . '" size="100"><br />
Mode: <select name="mode" value="' . $mode . '">
<option >PHP</option>
<option>mSL</option>
</select>
<input type="submit" name="Submit" value="Test!">
</form>';

if (!$regex || !$text) { echo "Please enter the regex and text you want to test\n"; exit; }

if (ereg($regex,$text,$matches) === FALSE) { echo "<font color=\"red\">The regex <i>" . $regex . "</i> with text <i>" . $text . "</i> is NOT working.</font>\n"; }

elseif (ereg($regex,$text,$matches) == 0) { echo "<font color=\"orange\">The regex <i>" . $regex . "</i> with text <i>" . $text . "</i> seems to be working, but there were no matches.</font>\n"; }

elseif (ereg($regex,$text,$matches) >= 1) { echo "<font color=\"green\">The regex <i>" . $regex . "</i> with text <i>" . $text . "</i> is working correctly!</font>\n<br />Matches:<br />\n";

$x = 0;
while ($matches[$x]){
if ($mode == PHP || $mode == php) echo $x . ':' . $matches[$x] . '<br />';
else echo $x+1 . ':' . $matches[$x] . '<br />';
$x++;
}
if ($mode == PHP || $mode == php) echo '<br>Code:<br>ereg(' . "$regex" . ',' . "$text" . ',' . chr(36) . matches . ');';
else echo '<br>Code:<br>' . chr(36) . "regex($text,$regex)";
}
echo "</center>";
?>
Member Avatar
Did the green bottles really fall or were they pushed?!

Posted ImagePosted Image
I couldn't decide which I liked more, so I have both ^.^
Posted ImagePosted ImagePosted ImagePosted Image
Click on an Image to feed them! | Get One For Yourself!
Quote Post Goto Top Offline Profile
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · PHP Script Showcase · Next Topic »
Add Reply